Postgres (SQL) - drop database using the psql command
by
Jeremy Canfield |
Updated: August 15 2023
| Postgres (SQL) articles
If using the default posgres user account, I typically go with the following command. In this example, a database named "mydb" is dropped.
sudo -u postgres psql --command "drop database mydb"
If you have created a user account, the -u or --username option and --password flag can be used.
psql --username johndoe --password --command "drop database mydb"
Better yet, you can setup passwordless authentication using the hidden .pgpass file and then connect without the --password flag.
psql --username johndoe --dbname mydb --command "drop database mydb"
Did you find this article helpful?
If so, consider buying me a coffee over at