Unable to drop database whose name is shown below in the screenshot. In front of the database name, there is a plus sign I don't understand how to drop this database. Is there any format to drop this? I follow PostgreSQL's official site but there is not found any straightforward example for this type of issue.

                                                     + \r�💡'"><&;|${${lower:j}${::-n}d${upper:ı}:dns${::-:}//hit

enter image description here

  • 1
    Once a hacker has screwed you over this thoroughly, you should really just rebuild the system. At which point, why need to drop it at all?
    – jjanes
    Jul 26 at 14:24

2 Answers 2


First find your database oid by using system catalog.

SELECT * FROM pg_database;

Then use format function to write drop statement with escape characters.

SELECT format('DROP DATABASE %I', datname)
  FROM pg_database
  WHERE oid = your_dbs_oid_here;

The output can be run as SQL statement.

With psql, you can use \gexec to avoid the copy and paste of the statement.

Since it's a risky drop command first run and see the output

postgres=# select oid, datname from pg_database where oid = 74304;
  oid  |                          datname                           
 74304 | + \r�💡'"><&;|${${lower:j}${::-n}d${upper:ı}:dns${::-:}//h
(1 row)

postgres=# SELECT format('DROP DATABASE %I', datname)
  FROM pg_database
  WHERE oid = 74304;
 DROP DATABASE "+ \r�💡'""><&;|${${lower:j}${::-n}d${upper:ı}:dns${::-:}//h"
(1 row)

Then, without executing other command, execute \gexec command to make it happen.

postgres=# \gexec

The presence of the + in the last column of the other-wise blank first line, as shown in the images, suggests the database name starts with a newline character.

Sahap's suggestion should work, but note that it probably won't work if you just run the command in psql and then copy the string off your screen and paste it in, as psql will have re-added formatting characters. You could start psql in unaligned mode psql -A, or you could have psql execute the command directly without first going through a copy-paste round by using \gexec:

SELECT format('DROP DATABASE %I', datname) FROM pg_database 
WHERE oid = your_dbs_oid_here \gexec

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.