DBA Hub

📋Steps in this guide1/4

How to create a database in postgres - DBACLASS DBACLASS

creating database is super easy in postgres. use create database command to create a database. You can use different options with the create

postgresql configurationintermediate
by PostgreSQL
15 views
1

Overview

Creating a database in postgres is very easy and it takes just few seconds. create database command is used to create the database.In this tutorial we will show different option with create database command. > NOTE – > When we install and initialise postgres cluster, by default two template database will be created, one is template1( which is the standard system database) and template0 ( which is the secondary standard system database). whenever we create create database command by default it will use the template of template1.template0 database should never be altered. NOTE – > When we install and initialise postgres cluster, by default two template database will be created, one is template1( which is the standard system database) and template0 ( which is the secondary standard system database). whenever we create create database command by default it will use the template of template1.template0 database should never be altered. 1. Creating a database with default option:( Simplest command):
2

Section 2

2. Create database with specific tablespace: While mentioning tablespace name make sure the tablespace is already present in the postgres cluster:

Code/Command (click line numbers to comment):

1
2
3
4
5
postgres=# <span style="color: #ff0000;"><strong>create database DBATEST;</strong></span>
CREATE DATABASE

postgres=# <span style="color: #ff0000;"><strong>create database DBATEST with tablespace ts_postgres;</strong></span>
CREATE DATABASE
3

Section 3

3. Create database with options like encoding, and template — View database information from psql prompt:

Code/Command (click line numbers to comment):

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
postgres#<span style="color: #ff0000;"><strong>CREATE DATABASE "DBATEST"
WITH TABLESPACE ts_postgres
OWNER "postgres"
ENCODING 'UTF8'
LC_COLLATE = 'en_US.UTF-8'
LC_CTYPE = 'en_US.UTF-8'
TEMPLATE template0;

 </strong></span>

postgres=# <span style="color: #ff0000;"><strong>\l+</strong></span>

postgres=# <span style="color: #ff0000;"><strong>\list+</strong></span>

postgres# <span style="color: #ff0000;"><strong>select * from pg_database;

</strong></span>
4

Section 4

> << Note – alternatively database can be created using pgadmin GUI tool also >>> << Note – alternatively database can be created using pgadmin GUI tool also >>> SEE ALSO: - How To Install Postgres Database On Mac Os/Linux - How To Drop A Database In Postgres - How To Enable And Disable Archive Mode In Postgres - How To Move A Tablespace To New Directory In Postgres - How To Make A Postgres Database Readonly - How To Access Csv Files On File System Using File_fdw

Comments (0)

Please to add comments

No comments yet. Be the first to comment!