0

I am connected to the postgres database, as postgres user:

docker exec -it mycontainer psql -h localhost -U postgres

I see the databases:

postgres=# \l
                                 List of databases
   Name    |  Owner   | Encoding |  Collate   |   Ctype    |   Access privileges

-----------+----------+----------+------------+------------+--------------------
---
 postgres  | postgres | UTF8     | en_US.utf8 | en_US.utf8 | 
 srdb      | postgres | UTF8     | en_US.utf8 | en_US.utf8 | =Tc/postgres       
  +
           |          |          |            |            | postgres=CTc/postgr
es+
           |          |          |            |            | sruser=CTc/postgres
 template0 | postgres | UTF8     | en_US.utf8 | en_US.utf8 | =c/postgres        
  +
           |          |          |            |            | postgres=CTc/postgr
es
 template1 | postgres | UTF8     | en_US.utf8 | en_US.utf8 | =c/postgres        
  +
           |          |          |            |            | postgres=CTc/postgr
es
(4 rows)

I want to drop a table, but nothing happens:

postgres=# DROP DATABASE srdb

Maybe somebody else is connected? Let's check:

postgres-# SELECT * FROM pg_stat_activity

Nothing!

What am I doing wrong?

2

SQL statements may span multiple lines, so you need to mark the end of your statement with a semi-colon ; (or the less-used metacommand \g)

Your DROP DATABASE srdb was not sent to the server and neither was the SELECT * FROM pg_stat_activity, as far as psql is concerned, it's an unfinished single statement. Also notice how the prompt -# on the second line differs from the =# of the first line: it's a secondary prompt indicating a continuation of the input, see Prompting in psql.

  • I had tried with and without semicolon. No luck – dangonfast Jan 18 at 4:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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