Installing Postgres

Linux Windows

$ sudo apt install postgresql postgresql-contrib
$ sudo apt install libpq-dev
$ psql --version
$ sudo service postgresql status
$ sudo netstat -plunt |grep postgres    //Check port
tcp        0      0 127.0.0.1:5432          0.0.0.0:*               LISTEN      255/postgres        
$
          
Install Postgres on Windows

Create user, Login with User

When installing postgres on Windows/Linux, Installation scripts creates a local user=postgres, this user is used to login to postgres DB
User postgres is default user (created on system which have access to db)
Linux Windows

# cat /etc/passwd|grep postgres
postgres:x:105:109:PostgreSQL administrator,,,:/var/lib/postgresql:/bin/bash

// Change passwd Unix postgres user
$ su - postgres         //login to postgres user
$ sudo passwd postgres  //Change Unix password of postgres user

// Change passwd of DB User (inside postgres)
$ psql                  //login to db
psql (16.6 (Ubuntu 16.6-0ubuntu0.24.04.1))
Type "help" for help.

postgres=# \du
                             List of roles
 Role name |                         Attributes                         
-----------+------------------------------------------------------------
 postgres  | Superuser, Create role, Create DB, Replication, Bypass RLS

postgres=# ALTER USER postgres WITH PASSWORD 'new_password';    //Change password
ALTER ROLE
postgres=#
          

// Port provided at time of installation
C:\Users\user> netstat -ant | find "5432"
TCP    0.0.0.0:5432           0.0.0.0:0              LISTENING       InHost
TCP    [::]:5432              [::]:0                 LISTENING       InHost


// During installtion postgres creates user=postgres
// password is provided during installation only
C:\Users\user> psql -U postgres
Password for user postgres:

psql (17.3)
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.

postgres=#