I am a complete beginner with postgresql. I created a test database called iswdp and now I want to delete it. When I do:
dropdb iswdp
the command returns no output and when I \list the table iswdp is still there.
dropdb iswdp;
returns:
ERROR: syntax error at or near "dropdb" LINE 1: dropdb iswdp
I used:
SELECT pg_terminate_backend(pg_stat_activity.pid)
FROM pg_stat_activity
WHERE datname = current_database()
AND pid <> pg_backend_pid();
which I found from another stackoverflow post to disconnect from all databases then attempted dropdb iswdp again with the same result.
I'm stuck, can someone help me? I'm doing this on linux mint from the bash terminal.
Using the option -f or –force with dropdb command or FORCE with DROP DATABASE to drop the database, it will terminate all existing connections with the database. Similarly, DROP DATABASE FORCE will do the same. In the first terminal, create a test database and a database test, and connect to the database.
Go to edit connections and look at the database name. Switch the connection to a different database and then drop the database you wish.
Step 1: Log in to the server using the SQL Shell (psql) app. Step 2: Run the following query: SELECT datname FROM pg_database; psql runs the query against the server and displays a list of existing databases in the output.
Postgres has a different way to switch databases, you do so using one of its meta-commands. Once you are in the Postgres terminal, you enter using the psql command, you can switch databases with \connect <db_name> command or with the shorter \c <db_name> .
The command dropdb
is a command issued from a shell prompt. From a sql prompt (like psql
), you would want to issue a DROP DATABASE
command.
I recommend opening psql
and issuing DROP DATABASE iswdp;
. That should work.
You may get an error that looks like ERROR: cannot drop the currently open database
, which will happen if you connect to iswdp
and try to drop it. If that happens, try instead to connect to the postgres
database, and issue the same DROP DATABASE
command. It should work.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With