- How to start PostgreSQL in Linux?
- Method of Getting started with PostgreSQL in Ubuntu 20.04:
- Step # 1: Get your System Ready for PostgreSQL Installation:
- Step # 2: Run the Installation Command for PostgreSQL:
- Step # 3: Verify the Active Status of PostgreSQL:
- Step # 4: Start PostgreSQL by Accessing its Server:
- Step # 5: Enter the PostgreSQL Console:
- Additional Tip:
- Tip # 1: How to Exit from the PostgreSQL Console?
- Tip # 2: How to Logout from the PostgreSQL Server?
- Conclusion:
- About the author
- Aqsa Yasin
- TablePlus
How to start PostgreSQL in Linux?
Whenever we talk about working with the databases in any operating system, the database management systems (DBMS) are always discussed. PostgreSQL is also a DBMS that falls in the category of relational database management systems, i.e., it deals with the management and working of relational databases. This relational DBMS offers the flexibility of creating and manipulating the databases and installing them on any famous operating system, i.e., Linux, macOS, and Windows. This is exactly why this DBMS is all the more famous across many programmers out there.
This relational DBMS is free and open-source, contributing more to its wide usage within the different industrial sectors. Moreover, the kind of transactions that this DBMS deals with is ACID, i.e., it can efficiently perform the transactions with ACID properties (atomicity, consistency, isolation, and durability). It means that if you have the data with these properties and want to create a relational database for it, you should definitely consider using the PostgreSQL server.
Since the launch of this relational DBMS back in 1996, it has undergone several upgrades, which is why its functionality is comparable with any of the latest relational database management systems. Moreover, this DBMS also provides enhancements in the traditional database management systems’ features and perfect compliance with SQL. This relational DBMS supports a wide range of native data types and some user-defined data types. In addition to that, it also handles the different versions of your databases while maintaining their concurrency in an extremely graceful manner.
The concept of inheritance also works well with the tables created within the databases of this DBMS. It means that you can let a table inherit its parent table’s properties very conveniently while using the PostgreSQL server. Other than that, this DBMS also allows you to back up your data online, preventing any data losses. Moreover, it also supports point-in-time recovery for easier access to the recovered data. By now, we have sufficiently discussed the relevant features of the PostgreSQL server. Now, it is the right time to talk about the actual focus of this article.
This article intends to teach you the installation procedure of the PostgreSQL server on a Linux distribution, i.e., Ubuntu 20.04. You can also use any other Linux flavor of your choice if you wish so. However, the method shared below will work perfectly well with a Ubuntu 20.04 system.
Method of Getting started with PostgreSQL in Ubuntu 20.04:
For getting started with PostgreSQL on a Ubuntu 20.04 system, you need to perform the following steps in the specified order:
Step # 1: Get your System Ready for PostgreSQL Installation:
Before we install anything on any Linux distribution, it is highly recommended to have an updated system. This goal can be achieved with the help of the command stated below:
Step # 2: Run the Installation Command for PostgreSQL:
Once the above-mentioned command has finished its execution, the next step is to execute the following command in your Ubuntu 20.04 terminal:
This command will install PostgreSQL on our Ubuntu 20.04 system, which is mandatory for us, i.e., we will not be able to start it if it is not installed on our Ubuntu 20.04 system.
With this command, you will be able to install PostgreSQL on your system very conveniently, and this whole process will take a few minutes to complete; however, we already had it installed on our system. Therefore, we were presented with the message shown in the image below once we executed the command mentioned above on our Ubuntu 20.04 system:
However, once you are installing the PostgreSQL server on your Ubuntu 20.04 system (if it is not already installed on it), then during the installation, you will be asked once to confirm your action. Once you will do that, the installation process of the PostgreSQL server will continue on your Ubuntu 20.04 system, and it will terminate upon a successful installation hence displaying a success message on the terminal.
Step # 3: Verify the Active Status of PostgreSQL:
We also need to verify that the PostgreSQL server is active on our system. For that, we can check its status with the following command:
The output presented in the image shown below verifies that PostgreSQL is active on our system. However, a point to be noted over here is that this server is not running now. It will only run once we start this server. This is exactly why the status turned out to be “active (exited)” instead of “active (running)”.
Step # 4: Start PostgreSQL by Accessing its Server:
After verifying the status of the PostgreSQL server on our Ubuntu 20.04 system, we will access this server so that it can start running with the help of the following command:
Your PostgreSQL server will immediately start running on your Ubuntu 20.04 system as soon as this command is executed. You can confirm this by taking a look at the changed path on your system’s terminal.
Step # 5: Enter the PostgreSQL Console:
Finally, for playing around with the databases, we need to enter the PostgreSQL console, which can be done with the command shown below:
You can see the PostgreSQL console in the following image:
After entering this console, you can instantly start working with databases by executing different queries of your choice in this console.
Additional Tip:
As an additional tip, we would like to teach you how to go back to your normal terminal in Ubuntu 20.04. For that, you first need to exit from the PostgreSQL console, after which you will have to log out from the PostgreSQL server. This can be done by following the two tips shared below:
Tip # 1: How to Exit from the PostgreSQL Console?
For exiting from the PostgreSQL server’s console, you need to type “\q” in that console and press the Enter key as shown in the following image:
Once you will do that, you will be out of the PostgreSQL server’s console.
Tip # 2: How to Logout from the PostgreSQL Server?
Now for logging out of the PostgreSQL server, you need to run the command shown below:
When you run this command, you will be successfully logged out of the PostgreSQL server.
Conclusion:
You can easily realize from this tutorial how simple it is to start PostgreSQL on a Linux system. We have used a Ubuntu 20.04 system for explaining this method. The main thing that you need to have is the PostgreSQL server installed on your system. If you have installed it on your system and its status is active, then it is just a matter of a few seconds for you to start this server on your system. Moreover, as an additional tip, we also taught you how to get out of the PostgreSQL server’s console and how to log out of this server.
About the author
Aqsa Yasin
I am a self-motivated information technology professional with a passion for writing. I am a technical writer and love to write for all Linux flavors and Windows.
TablePlus
In this post, we are going to figure out how to start, stop, and restart a PostgreSQL server on macOS, Linux, and Windows.
If you installed PostgreSQL via Homebrew:
pg_ctl -D /usr/local/var/postgres start
pg_ctl -D /usr/local/var/postgres stop
brew services start postgresql
brew services stop postgresql
If you want a hassle-free way to manage the local PostgreSQL database servers, use DBngin. It’s just one click to start, another click to turn off. No dependencies, no command line required, multiple drivers, multiple versions and multiple ports. And it’s free.
2. On Windows
First, you need to find the PostgreSQL database directory, it can be something like C:\Program Files\PostgreSQL\10.4\data . Then open Command Prompt and execute this command:
pg_ctl -D "C:\Program Files\PostgreSQL\9.6\data" start
pg_ctl -D "C:\Program Files\PostgreSQL\9.6\data" stop
pg_ctl -D "C:\Program Files\PostgreSQL\9.6\data" restart
- Open Run Window by Winkey + R
- Type services.msc
- Search Postgres service based on version installed.
- Click stop, start or restart the service option.
Update and install PostgreSQL 10.4
sudo apt-get update sudo apt-get install postgresql-10.4
By default, the postgres user has no password and can hence only connect if ran by the postgres system user. The following command will assign it:
sudo -u postgres psql -c "ALTER USER postgres PASSWORD 'postgres';" sudo -u postgres psql -c "CREATE DATABASE testdb;"
sudo service postgresql start
sudo service postgresql stop
Need a good GUI tool for PostgreSQL on MacOS and Windows? TablePlus is a modern, native tool with an elegant GUI that allows you to simultaneously manage multiple databases such as MySQL, PostgreSQL, SQLite, Microsoft SQL Server and more.