Postgresql – Drop database owned by specific user in PostgreSQL

postgresql

I have created database with bad symbols at the end of its name.
Now I want to drop it but I don't know how to type its name in the console.
Can I remove databases owned by this user? I tried to DROP OWNED BY devuser but it does not worked. I see just DROP OWNED in the console.

command prompt

Best Answer

You could also try this from your shell:

-bash-4.1$ bad_dbname=$(psql -t -q -c "select datname from pg_database where datname like 'bsw_ui%' limit 1")
-bash-4.1$ echo "the next command will drop ${bad_dbname}"
-bash-4.1$ psql -c "drop database ${bad_dbname}"

I verified this works using bash4.1 on centos6.3 with posgresql8.4 for a database using this unicode character. YMMV