Easily create or drop a database via the psql CLI using the below syntax.
Create a PostgreSQL Database: Just modify the database_name to the name you prefer for your new database.
- create database database_name
Delete a PostgreSQL Database: Again just modify the database_name to the name of the database you would like to remove from Postgres.
- drop database database_name
Below is output from a shell where a connection is made to Postgres with psql, a database is added, and then the same database is deleted. In the example below the database that is added and removed is called “newdb”.
- [root@server ~]# psql -U postgres
- Welcome to psql 8.3.5, the PostgreSQL interactive terminal.
- Type: \copyright for distribution terms
- \h for help with SQL commands
- \? for help with psql commands
- \g or terminate with semicolon to execute query
- \q to quit
- postgres=# create database newdb;
- CREATE DATABASE
- postgres=# drop database newdb;
- DROP DATABASE
- postgres=# \q
- [root@server ~]#
Please search the rest of www.question-defense.com for more PostgreSQL information. If you have other questions feel free to post them in the forum or add them to the comment section of any post and we will reply with a resolution or a request for more information.