HomeWindowsDefault Postgres Port

Default Postgres Port

You can manage your PostgreSQL database through the web interface, but you must use the default Postgres port. PostgreSQL is a fast database known for its power and support for JSON file formats. However, to configure the PostgreSQL Database service on localhost, you may need to use Postgres default port of 5432.

On the other hand, this port can be easily changed from the Postgresql.conf configuration file, which serves as the database’s primary configuration file. 5432 is a TCP port for the PostgreSQL database, but if the server is running on a Linux instance, the database may also use a local socket in addition to the port. The local socket is the best way to connect to a database because it eliminates the need to create a TCP connection during data transformation.

In this post, we will talk about how to change the default PostgreSQL port so that you can create as many databases as you want.

What is Postgres Database?

Postgres is an open-sourced database that we also know as PostgreSQL. It is a relational, enterprise-level, and advanced database that supports SQL and NoSQL queries, such as JSON. Postgres has been around for almost 3 decades because of its stability in storing a huge amount of data for different organizations. Developers use Postgres for creating mobile and web applications and analytic applications.

In 1986, the University of California started the Postgres project for the first time, but initially, the project was known as POSTGRES. During that time, the project was designed to add minimal features supporting different kinds of data. In 1996, PostgreSQL demonstrated that it is up to support rational data queries. Since then, it has become famous for Windows, Mac, Solaris, and other computer systems.

Postgres supports programming languages like Python, Java, Ruby, Node.js, C#, C++, etc. And it offers features like table inheritance, Multi-version concurrency control (MVCC), foreign key referential integrity, user-defined data types, and more. To get the most out of Postgres, you will have to edit its configuration file, where you can define your data type, functional languages, and index types. And that postgresql.conf File will also allow you to modify the Postgres port for extra security purposes.

About Configuring the postgresql.conf File-

To connect to a PostgreSQL database server from a remote system, the only thing you can do is use the TCP connection. It uses the local socket with higher latency but limits network bandwidth usage. You should configure the PostgreSQL Server first to use the local socket or TCP connections. And to configure the server, you will have to edit the postgresql.conf file. You will have to find out the file’s exact location, which depends on the operating system and PostgreSQL version. If you are running the Linux system, you will have to run a command that will help you find the file:

locate postgresql.conf

/etc/postgresql/9.5/main/postgresql.conf

The server’s version is added to the file’s path here, and you must ensure the path before opening the file. The Windows system displays the path as C:Program FilesPostgreSQL9.5data, and you must always look for the version. However, if you are using a Linux distribution, the following command should be used to open the configuration file:

vi /etc/postgresql/9.5/main/postgresql.conf

Using the unix_socket_directory feature, you can configure the local socket on Linux, and it will display the path of the filesystem and the possible location of the socket in the directory. To create the socket on a particular file system path, specify a directory usually in /var/run/postgresql/most of the time. The socket will be added to this directory when you commence the server following the time. You can either remove or add (#) to the following line to disable socket access:

unix_socket_directory= /var/run/postgresql/

Now, restart the server, and the changes will be applied:

service postgresql restart

But these steps are for configuring Postgres. If you want to change the PostgreSQL Port Number, follow the next method.

How to Change the PostgreSQL Port Number?

Surround SCM provides a default port number of 5432 after the installation of PostgreSQL. PostgreSQL will not work correctly if the port number is changed during installation. You can change the port number if another application uses the same port after installation. Here is how to change PostgreSQL port number:

  1. First, stop the Surround SCM Server if it is currently running.
  2. And you should also stop the PostgreSQL service to change the port number if it is currently running.
  3. Open the PostgreSQL configuration file in a text editor. Its file location is possibly C:Program FilesPostgreSQLversion > data
  4. In the Connections and Authentication sector of the file, you can change the port number from 5432 to anything else you want.
  5. Click on File > Save and save the new number.
  6. Click on Windows Start.
  7. Type Run in the search box and launch the program.
  8. Enter regedit in the run box and press Enter.
  9. The Windows Registry Editor will open up.
  10. Now find the SCM Server directory, which’s default location is MY Computer. Seapine SoftwareSurround SCM SCM Server HKEY_LOCAL_MACHINESOFTWARES
  11. Then click on the DBPort registry.
  12. Click on Edit > Modify.
  13. Do you remember the new port number you set earlier? You will need to combine it with the value data.
  14. Press OK.
  15. Restart the PostgreSQL service and the Surround SCM Server.

Conclusion

That was all about changing the default PostgreSQL port number, but managing your PostgreSQL database is a much bigger topic. To connect to your PostgreSQL database using the default port, you’ll need to use some complex commands in your text editor. Check out our other relevant articles if you want to know how to manage a PostgreSQL database using the default Postgres port.

People are also reading:

Vijay Singh Khatri
Vijay Singh Khatri
Graduate in Computer Science, specialized in Digital Marketing. I am very fond of writing tech articles and creating my own blog to teach my audience.

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular