Creating the database in PostgreSQL is a very simple task, it's like creating a directory structure. We will discuss the steps to create a new database.
Login to the Postgres instance using the admin account
Login to the Postgres instance using the admin account
$ psql
-d postgres -U postgres
psql.bin (9.6.2.7)
postgres=#
Create a database using the below command
postgres# create database tech_db;
The above command will take parameters by default, full syntax is defined below
create database database name
owner=role_name
template
= template
encoding
= encoding
lc_collate
=collate
lc_ctype
= ctype
tablespace
= tablespace_Name
connection_limit
= max_concurrent_connections
By using default parameters database can be created with the below command
postgres=# create database tech_db;
CREATE DATABASE
postgres=#
CREATE DATABASE
postgres=#
The list of the database can be checked using \l or pg_database table
postgres=# \l
List of databases
Name | Owner | Encoding | Collate | Ctype | Access privileges
-----------+----------+----------+----------------------------+----------------------------+-----------------------
postgres | postgres | UTF8 | English_United States.1252 | English_United States.1252 | =Tc/postgres +
| | | | | postgres=CTc/postgres
tech_db | postgres | UTF8 | English_United States.1252 | English_United States.1252 |
template0 | postgres | UTF8 | English_United States.1252 | English_United States.1252 | =c/postgres +
| | | | | postgres=CTc/postgres
template1 | postgres | UTF8 | English_United States.1252 | English_United States.1252 | =c/postgres +
| | | | | postgres=CTc/postgres
(4 rows)
postgres=# select datname from pg_database;
datname
-----------
template1
template0
postgres
tech_db
(4 rows)
postgres=#
List of databases
Name | Owner | Encoding | Collate | Ctype | Access privileges
-----------+----------+----------+----------------------------+----------------------------+-----------------------
postgres | postgres | UTF8 | English_United States.1252 | English_United States.1252 | =Tc/postgres +
| | | | | postgres=CTc/postgres
tech_db | postgres | UTF8 | English_United States.1252 | English_United States.1252 |
template0 | postgres | UTF8 | English_United States.1252 | English_United States.1252 | =c/postgres +
| | | | | postgres=CTc/postgres
template1 | postgres | UTF8 | English_United States.1252 | English_United States.1252 | =c/postgres +
| | | | | postgres=CTc/postgres
(4 rows)
postgres=# select datname from pg_database;
datname
-----------
template1
template0
postgres
tech_db
(4 rows)
postgres=#
Your database is ready to use. There is other way as well to create
database using createdb command and need to run from UNIX shell, will be discussed later on
This is an exclusive post about PostgreSQL and the use of foreign data wrapper actually overcomes and helps people solve the most complex problems and errors.
ReplyDeleteSSIS postgresql read