Проверить запущен ли postgresql linux

Проверить запущен ли postgresql linux

PostgreSQL is a widely used relational database because of its basic to advanced features. One of the notable features of Postgres is that it is compatible with various operating systems, such as Windows, Linux, and MacOS. It assists users in storing, managing, and retrieving large amounts of data efficiently. To get the maximum of Postgres features, it is necessary to learn how to start or stop the Postgres server on ubuntu.

This post is going to present a step-by-step guide on how to start or stop the PostgreSQL server on the Ubuntu operating system.

How to Start or Stop PostgreSQL Server on Ubuntu?

In Ubuntu, the Postgres server can be started or stopped using various methods. In this article a couple of well-known methods will be discussed to start or restart the Postgres server on Linux (Ubuntu):

  • Method 1: Using the “systemctl” Command
  • Method 2: Using the “/etc/init.d/postgresql” which is the script that systemctl calls.

Method 1: Start and Stop Postgres Server Using the “systemctl” Command

Here are the steps to start or stop the Postgres server on ubuntu using the “systemctl” command:

Step 1: Review the Postgres Status

Open the terminal and execute the following “sudo” command to review the current status of the Postgres server:

sudo systemctl status postgresql

img

The above snippet shows that the Postgres server is currently deactivated.

Step 2: Start the Postgres Server

Use the below-given “sudo” command with the “start” option to begin the Postgres server:

sudo systemctl start postgresql

img

The output illustrates that the Postgres server has been initiated successfully.

Step 3: Verify the Postgres Status

Use the below-given “sudo” command along with the “status” option to verify the Postgres status:

sudo systemctl status postgresql

img

The output confirms that the Postgres Server has been activated successfully.

Step 4: Stop the Postgres Server

Type the “systemctl” command followed by the “stop” option to halt the Postgres server:

sudo systemctl stop postgresql

img

The output shows that the Postgres server has been stopped successfully.

Step 5: Confirm Postgres Status

Type the “systemctl” command followed by the “status” option to confirm the Postgres status:

sudo systemctl status postgresql

img

The output proves that the Postgres server has been deactivated successfully.

Method 2: Start and Stop Postgres Server Using “/etc/init.d/postgresql”

To start or stop a Postgres server on Ubuntu, follow the below-given instructions:

Step 1: Review the Postgres Status

Open the terminal and execute the following command to review the current status of the Postgres server:

/etc/init.d/postgresql status

img

The above snippet states that the Postgres server is not active yet.

Step 2: Start the Postgres Server

Читайте также:  What is incremental backup in linux

Use the “/etc/init.d/postgresql” command with the start option to initiate the Postgres server:

img

The output shows that the Postgres server has been started successfully.

Step 3: Verify the Postgres Status

Use the “/etc/init.d/postgresql” command with the “status” option to verify the Postgres status:

/etc/init.d/postgresql status

img

The output demonstrates that the Postgres Server has been activated/started successfully.

Step 4: Stop the Postgres Server

Type the “/etc/init.d/postgresql” command followed by the “stop” option to halt the Postgres server:

img

The output shows that the Postgres server has been stopped successfully.

Step 5: Confirm Postgres Status

Type the “/etc/init.d/postgresql” command followed by the “status” option to confirm the Postgres status:

/etc/init.d/postgresql status

img

The output proves that the Postgres server has been stopped successfully.

In Ubuntu, “/etc/init.d/postgresql” and the “systemctl” commands are used with the “start” or “stop” option to activate or deactivate the Postgres server, respectively. The status of the Postgres server can be confirmed by executing these commands with the “status” option. This article has presented a step-by-step guide on how to start or stop the PostgreSQL server on the Ubuntu operating system.

Источник

How to Check that PostgreSQL Server is Running on Linux (Ubuntu/Debian/Red Hat/Fedora)

Check PostgreSQL Server Running

This tutorial will show you how to check that the PostgreSQL Server service is running on your Linux system.

Checking PostgreSQL is Running on Ubuntu/Debian

To check whether the PostgreSQL server service is running successfully on your Debian or Ubuntu system, run:

sudo systemctl status postgresql

Checking the Firewall

By default PostgreSQL runs on port 5432 and is not restricted by host name.

When installing PostgreSQL on Ubuntu, usually a firewall rule will be created automatically allowing access to the database server.

You can confirm this by running the nmap command:

This will show the ports and service that are open on your machine – check through the list and make sure that postgresql is listed next to the port number 5432.

PORT STATE SERVICE 80/tcp open http 631/tcp open ipp 5432/tcp open postgresql

If it is not listed, you can open the firewall port using the ufw command:

If you have configured different a different hostname or port from the default, you may need to update your firewall rules to match.

Checking PostgreSQL is Running on Arch Linux

The process to check whether PostgreSQL is running is the same on Arch Linux, simply run:

sudo systemctl status postgresql

Checking the Firewall

Again, the nmap command is useful here for checking that the default PostgreSQL port of 5432 is open on your system:

Which will output something like:

PORT STATE SERVICE 80/tcp open http 631/tcp open ipp 5432/tcp open postgresql

If this port is not on the list, use ufw to allow the port through the firewall:

If you’ve changed from the default PostgreSQL port in your configuration, you will need to adjust your firewall rule to match.

Checking PostgreSQL is Running on Red Hat, Fedora, Centos, etc

Like Ubuntu and Arch, you can use the systemctl command to check the status of the PostgreSQL service on Red Hat based distributions:

sudo systemctl start postgresql.service

Checking the Firewall

The firewall-cmd command can be used to check that the default PostgreSQL port of 5432 is open on Red Hat based distributions:

Читайте также:  Не устанавливается grub при установке linux mint

postgressql and its port should be shown in the outputted list. If it is not, you can grant the PostgreSQL service network access through the firewall by running:

firewall-cmd --zone=public --permanent --add-service=postgresql
firewall-cmd --zone=public --permanent --add-port 5432/tcp

Once changes have been made, apply them by reloading the firewall rules:

Other Linux Distributions

Most modern Linux distributions (based on systemd) will use the same systemctl syntax as above to check whether a service is running.

Checking the Firewall

In the unlikely scenario where you do not have access to ufw or firewall-cmd, you can write your own iptables rules to allow traffic through your systems firewall.

To continue your PostgreSQL journey, head back to our index that lists our full PostgreSQL guide.

I’m Brad, and I’m nearing 20 years of experience with Linux. I’ve worked in just about every IT role there is before taking the leap into software development. Currently, I’m building desktop and web-based solutions with NodeJS and PHP hosted on Linux infrastructure. Visit my blog or find me on Twitter to see what I’m up to.

Leave a Comment Cancel reply

SHARE:

RECENT ARTICLES

We use cookies on our website to give you the most relevant experience by remembering your preferences and repeat visits. By clicking “Accept”, you consent to the use of ALL the cookies.

Privacy Overview

This website uses cookies to improve your experience while you navigate through the website. Out of these, the cookies that are categorized as necessary are stored on your browser as they are essential for the working of basic functionalities of the website. We also use third-party cookies that help us analyze and understand how you use this website. These cookies will be stored in your browser only with your consent. You also have the option to opt-out of these cookies. But opting out of some of these cookies may affect your browsing experience.

Necessary cookies are absolutely essential for the website to function properly. This category only includes cookies that ensures basic functionalities and security features of the website. These cookies do not store any personal information.

Any cookies that may not be particularly necessary for the website to function and is used specifically to collect user personal data via analytics, ads, other embedded contents are termed as non-necessary cookies. It is mandatory to procure user consent prior to running these cookies on your website.

Источник

Check PostgreSQL Service Status

This article will show some alternative or the way to check whether the PostgreSQL service in a host, server or workstation is actually active or not.

It is an important thing to do before any other things can be done especially connecting to PostgreSQL Database Server on the machine either locally or remotely.

By detecting whether the status of the service is actually active or not, it doesn’t take any longer just to spend and wasting time whether the connection to the PostgreSQL Database server can be initiated or not.

Читайте также:  Linux понизить версию ядра

First of all, check whether PostgreSQL Database Server has already installed or not. It is important but this step can be skipped if it has already ensured that it really has. Be sure to check it and in Ubuntu Linux operating system, it can be done by using ‘apt’ command which can be read in the article about ‘List Installed Program in Ubuntu Linux using apt command’, if the operating system used is Ubuntu or any variant of Debian operating system distribution.

After that, in order to check the service whether it is active or not, it is important to know the service name which represents PostgreSQL Database Server. It can be done in several Linux operating system distribution by checking the service configuration file which is normally located in /etc depends on the Linux variant used. Type the following command to do that :

cat /etc/service | grep 5432

If PostgreSQL database server has already installed and it is configured to listen and handle request in port 5432, below is the possible outcome which is going to be shown by executing the above command in the bash prompt terminal :

user@hostname:~# cat /etc/services | grep 5432 postgresql 5432/tcp postgres # PostgreSQL Database postgresql 5432/udp postgres user@hostname:~#

It is understandable from the output shown above where the service name is ‘postgresql’. The next thing to do is checking whether that service name called ‘postgresql’ is active or at least the port which is assigned to the service is active and listening for processing request.

This is how to check whether the service is active or not :

service postgresql status

This is when it is executed in the bash prompt terminal and turned out the service is active :

user@hostname:~$ service postgresql status ● postgresql.service - PostgreSQL RDBMS Loaded: loaded (/lib/systemd/system/postgresql.service; enabled; vendor preset: enabled) Active: active (exited) since Min 2016-09-25 16:51:50 WIB; 2h 5min ago Process: 13371 ExecStart=/bin/true (code=exited, status=0/SUCCESS) Main PID: 13371 (code=exited, status=0/SUCCESS) Tasks: 0 Memory: 0B CPU: 0 CGroup: /system.slice/postgresql.service Sep 25 16:51:50 hostname systemd[1]: Starting PostgreSQL RDBMS. Sep 25 16:51:50 hostname systemd[1]: Started PostgreSQL RDBMS. user@hostname:~$

The other thing which is an alternative way to do it is by checking whether a specific port assigned for service relates to PostgreSQL Database Server is actively listening or not by executing the following command :

The possible outcome if the PostgreSQL Database Server is running and it is configured to listen incoming request in port 5432 is shown below :

user@hostname:~$ netstat -tulpn | grep 5432 (Not all processes could be identified, non-owned process info will not be shown, you would have to be root to see it all.) tcp 0 0 127.0.0.1:5432 0.0.0.0:* LISTEN - user@hostname:~$

It is stated by the output above that in there is an open port which is listen for incoming request in localhost at port 5432.

Источник

Оцените статью
Adblock
detector