How to Install PgSQL (Postgres SQL) in windows

Step 1: Download Executable files
Download respective binaries for 32 Bit or 64 bit of latest available version

https://www.postgresql.org/

Step 2: Install the binaries

Once binary is downloaded and installed in the computer with respective username of windows user. 

Installation Directory: D:\PgSQL
Server Installation Directory: D:\PgSQL
Data Directory: D:\PgSQL\data
Database Port: 5432
Database Superuser: postgres
Operating System Account: NT AUTHORITY\NetworkService
Database Service: postgresql-x64-11
Command Line Tools Installation Directory: D:\PgSQL
pgAdmin4 Installation Directory: D:\PgSQL\pgAdmin 4
Stack Builder Installation Directory: D:\PgSQL

Step 3: Start the Postgres Service

D:\PgSQL>pg_ctl -D d:\pgsql\data initdb
The files belonging to this database system will be owned by user “mudhalvan”.
This user must also own the server process.

The database cluster will be initialized with locale “English_United States.1252”.
The default database encoding has accordingly been set to “WIN1252”.
The default text search configuration will be set to “english”.

Data page checksums are disabled.

fixing permissions on existing directory d:/pgsql/data … ok
creating subdirectories … ok
selecting default max_connections … 100
selecting default shared_buffers … 128MB
selecting dynamic shared memory implementation … windows
creating configuration files … ok
running bootstrap script … ok
performing post-bootstrap initialization … ok
syncing data to disk … ok

WARNING: enabling “trust” authentication for local connections
You can change this by editing pg_hba.conf or using the option -A, or
–auth-local and –auth-host, the next time you run initdb.

Success. You can now start the database server using:

d:/pgsql/bin/pg_ctl -D d:/pgsql/data -l logfile start

D:\PgSQL>

Step 4: Start the Database server

D:\PgSQL>pg_ctl -D d:/pgsql/data -l logfile start
waiting for server to start…. done
server started

D:\PgSQL>

Step 5: Create Database

D:\PgSQL\bin>createdb -h localhost -U mudhalvan testdb01

Step 6: Connect to the database

D:\PgSQL\bin>psql -U mudhalvan testdb01 -h localhost
psql (11.1)
WARNING: Console code page (437) differs from Windows code page (1252)
8-bit characters might not work correctly. See psql reference
page “Notes for Windows users” for details.
Type “help” for help.

To List the databases

testdb01=# \l

Step 7: Create Table

testdb01=# create table emp (eno integer,ename char(10));
CREATE TABLE

Step 8: Describe the Table

testdb01=# \d emp
Table “public.emp”
Column | Type | Collation | Nullable | Default
——–+—————+———–+———-+———
eno | integer | | |
ename | character(10) | | |

Step 9: Insert the record into Table
testdb01=# insert into emp values(1,’Mudhalvan’);
INSERT 0 1
testdb01=# select * from emp;
eno | ename
—–+————
1 | Mudhalvan
(1 row)

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.