SoFunction
Updated on 2025-04-08

A brief discussion on what you don't know about Postgresql default port 5432

Regarding the definition of Postgresql port 5432:

Port 5432 has been registered with IANA (The Internet Assigned Numbers Authority),

And assign this port uniquely to Postgres.

This means that a server with Linux OS installed will have this reserved port even if the postgresql database has not been installed.

The method to view this reserved port is as follows:

new@newdb-> cat /etc/services |grep 5432
postgres  5432/tcp  postgresql  # POSTGRES
postgres  5432/udp  postgresql  # POSTGRES

The /etc/services file contains the mapping between the service name and the port number, and many system programs need to use this file.

Generally speaking, do not modify the contents of the file, because these settings are Internet-standard settings.

Once modified, it may cause system conflicts and prevent users from accessing resources normally.

Supplement: PostgreSQL command interface

The psql client program provides a command line interface to the PostgreSQL server. It uses command line parameters to control the functions enabled in the client interface.

The administrator account name of PostgreSQL is postgres. Because PostgreSQL uses a Linux user account to verify users, you must log in as a Linux account postgres to access the PostgreSQL server as a postgres user.

Because the postgres user account is a special account, it should not be assigned a password. This way no one can break into the system using the postgres account.

If you want to log in with your postgres account, you must be the root account and then use the su command to change it to the postgres user.

There are two types of commands that psql programs can use:

Standard SQL statements

PostgreSQL metacommand

Commonly used PostgreSQL metacommands:

\lList available databases

\cConnect to a database

\dtList tables in a database

\duList PostgreSQL users

\zList table permissions

\?List all available metacommands

\hList all available SQL commands

\qExit the database

PostgreSQL user accounts are different from accounts in MySQL. The login account in PostgreSQL is called the login role. The PostgreSQL server matches the login role with the Linux system user account.

The above is personal experience. I hope you can give you a reference and I hope you can support me more. If there are any mistakes or no complete considerations, I would like to give you advice.