Проверить работает ли postgresql linux

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.

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 :

Читайте также:  Arch linux no ifconfig

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.

Источник

Проверить работает ли postgresql linux

pg_isready — check the connection status of a PostgreSQL server

Synopsis

pg_isready [ connection-option . ] [ option . ]

Description

pg_isready is a utility for checking the connection status of a PostgreSQL database server. The exit status specifies the result of the connection check.

Options

Specifies the name of the database to connect to. The dbname can be a connection string. If so, connection string parameters will override any conflicting command line options.

Specifies the host name of the machine on which the server is running. If the value begins with a slash, it is used as the directory for the Unix-domain socket.

Specifies the TCP port or the local Unix-domain socket file extension on which the server is listening for connections. Defaults to the value of the PGPORT environment variable or, if not set, to the port specified at compile time, usually 5432.

Do not display status message. This is useful when scripting.

The maximum number of seconds to wait when attempting connection before returning that the server is not responding. Setting to 0 disables. The default is 3 seconds.

Connect to the database as the user username instead of the default.

Print the pg_isready version and exit.

Show help about pg_isready command line arguments, and exit.

Exit Status

pg_isready returns 0 to the shell if the server is accepting connections normally, 1 if the server is rejecting connections (for example during startup), 2 if there was no response to the connection attempt, and 3 if no attempt was made (for example due to invalid parameters).

Environment

pg_isready , like most other PostgreSQL utilities, also uses the environment variables supported by libpq (see Section 34.15).

Читайте также:  Raid types in linux

The environment variable PG_COLOR specifies whether to use color in diagnostic messages. Possible values are always , auto and never .

Notes

It is not necessary to supply correct user name, password, or database name values to obtain the server status; however, if incorrect values are provided, the server will log a failed connection attempt.

Examples

$ pg_isready /tmp:5432 - accepting connections $ echo $? 0 

Running with connection parameters to a PostgreSQL cluster in startup:

$ pg_isready -h localhost -p 5433 localhost:5433 - rejecting connections $ echo $? 1 

Running with connection parameters to a non-responsive PostgreSQL cluster:

$ pg_isready -h someremotehost someremotehost:5432 - no response $ echo $? 2 

Submit correction

If you see anything in the documentation that is not correct, does not match your experience with the particular feature or requires further clarification, please use this form to report a documentation issue.

Copyright © 1996-2023 The PostgreSQL Global Development Group

Источник

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:

Читайте также:  Astra linux настройки bios

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.

Источник

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