PostgreSQL Create Database
Description
This document discusses how to create a database in PostgreSQL using the command line, pgAdmin III, and phppgAdmin. For ease of understanding, each process is complemented by screenshots taken while doing.
Create Database using command line in Linux
Start terminal and execute the followingcommand:
sudo -u postgres psql postgres
Now run the following command to create a database.
createdb w3r
This command creates a database w3r.
The following table describes errors you may encounter while creating a database using "createdb".
Error | Description |
---|---|
createdb: command not found | This may happen if POstgreSQL is not installed properly or your shell’s search path was not set to include it. You need to run createdb command from the absolute path of your POstgreSQL installation path. |
createdb: could not connect to database postgres: could not connect to server: No such file Is the server running locally and accepting connections on Unix domain socket "/tmp/.s.PGSQL.5432"? | This may happen if PostgreSQL Server is not started properly or it was not started where the createdb command needs it to be started. |
createdb: could not connect to database postgres: FATAL: role "usr_name" does not exist | This may happen if the PostgreSQL user account is created. PostgreSQL user accounts are different from system user accounts. |
createdb: database creation failed: ERROR: permission denied to create database | If the PostgreSQL user account created does not have permission to create a database. In this case, you have to grant permissions to the associated user to execute createdb command. |
Create Database using pgAdmin III
Start pgAdmin III and (in linux from Application > Programs > pgAdmin III and in Windows All Programs > PostgreSQL 9.1 > pgAdmin III) and reach "Databases" under your Server menu in right-hand side pane of your pgAdmin III window. Right click on "Databases" and click on "New Database...". This will open a new window to create a new database. Supply necessary information and click "OK" to create a new Database. Remember to select the PostgreSQL user account whom you want to be the owner of the database.
There are other options available in this window like "Privileges", which we will discuss later on. This way you can create a new database in PostgreSQL using pgAdmin III.
Create Database using phppgadmin
phppgadmin is an easy to use tool for managing PostgreSQL. Now we will see how can we create a new database in phppgadmin.
Start your phppgadmin by pointing your browser to http://127.0.0.1/phppgadmin (replace 127.0.0.1 with your host if you are using any host other than localhost) and reach your server in the right hand side pane of your phppgadmin tool.
Now click "Create database" In the window opened, supply the name of the database and click "Create". Remember to select UTF 8 as Encoding if you don't have any special purpose to select any other encoding type.
This way you can create a new database in PostgreSQL using phppgadmin.
Previous: Data Types
Next: Create Tables
It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.
https://w3resource.com/PostgreSQL/create-database.php
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics