Restart postgres on linux

How to restart Postgresql

I have PostgreSQL 9.3 and 9.4 installed on my Linux Mint machine. How can I restart PostgreSQL 9.4? A method to restart both versions together is also fine.

@kometen The referenced article doesn’t provide a way to selectively start and stop each and every single instance.

@JanHenke I wouldn’t suggest anything outside the scope of the question. Anyway, v9.5 is the current stable version.

@Enzo He said he has both version running in parallel. So I just suggested migrating to the newer of the two, which would also fix the problem, as there would be only one postgresql left.

8 Answers 8

Try this as root (maybe you can use sudo or su ):

/etc/init.d/postgresql restart 

Without any argument the script also gives you a hint on how to restart a specific version

[Uqbar@Feynman ~] /etc/init.d/postgresql Usage: /etc/init.d/postgresql [version . ] 

Similarly, in case you have it, you can also use the service tool:

[Uqbar@Feynman ~] service postgresql Usage: /etc/init.d/postgresql [version . ] 

Please, pay attention to the optional [version . ] trailing argument. That’s meant to allow you, the user, to act on a specific version, in case you were running multiple ones. So you can restart version X while keeping version Y and Z untouched and running.

Finally, in case you are running systemd, then you can use systemctl like this:

[Uqbar@Feynman ~] systemctl status postgresql ● postgresql.service - PostgreSQL database server Loaded: loaded (/usr/lib/systemd/system/postgresql.service; enabled; vendor preset: disabled) Active: active (running) since Wed 2017-11-14 12:33:35 CET; 7min ago . 

You can replace status with stop , start or restart as well as other actions. Please refer to the documentation for full details. In order to operate on multiple concurrent versions, the syntax is slightly different. For example to stop v12 and reload v13 you can run:

systemctl stop postgresql-12.service systemctl reload postgresql-13.service 

Thanks to @Jojo for pointing me to this very one. Finally Keep in mind that root permissions may be needed for non-informative tasks as in the other cases seen earlier.

Источник

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.

DBngin local server

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.

Источник

Restart Postgres

Service management is a prevalent task for system administrators and power users. For example, one of the common tasks of a database or system administrator is ensuring that the database servers are running smoothly.

This tutorial explores the various methods and techniques that you can use to restart the PostgreSQL server on different systems.

NOTE: It is good to keep in mind that the steps and techniques that are discussed in this tutorial may vary depending on the target system, installed version, and installation method.

Restarting PostgreSQL on Linux

On Linux, there are several methods that you can use to restart the PostgreSQL server. However, these methods may require sudo permissions.

Using the Systemd

To restart PostgreSQL using the systemd, open the terminal and run the following command as follows:

Using the Service Command

You can also use the service command to restart PostgreSQL on Linux. The command is as follows:

Manual Restart

You can also perform a manual restart using the provided PostgreSQL binaries. The commands are as follows:

Open the terminal and locate the data directory for your PostgreSQL installation. The common locations are in /var/lib/postgresql//data or /var/lib/postgresql/data.

Run the following command to stop the PostgreSQL server:

Once the server is stopped, run the following command to start it back again.

This should bring back up the PostgreSQL server.

Restart PostgreSQL on MacOS

Similarly, the methods vary depending on the installation method in PostgreSQL.

Using Homebrew

If you installed PostgreSQL on macOS using Homebrew, you can use the Homebrew service manager as shown in the following command:

Restart PostgreSQL on Windows

On Windows, you can use two main methods to restart the PostgreSQL server.

Using the Command Prompt

Start by launching the command prompt as an administrator.

Next, navigate to the PostgreSQL bin directory. If you used the default install directory, head over to C:\Program Files\PostgreSQL\\bin.

Finally, run the following command to restart PostgreSQL:

This should restart the PostgreSQL server using the pg_ctl utility. Remember to replace the version with your installed PostgreSQL version.

Using the Windows Services

You can also use the Windows Service administration tool. To launch the Services Manager, press the Windows Key + R and type “services.msc”.

Locate the PostgreSQL service from the services window.

Right-click on the service and select “Restart”.

Conclusion

We explored the various methods and techniques that you can use to restart the PostgreSQL server on Linux, Windows, and macOS.

About the author

John Otieno

My name is John and am a fellow geek like you. I am passionate about all things computers from Hardware, Operating systems to Programming. My dream is to share my knowledge with the world and help out fellow geeks. Follow my content by subscribing to LinuxHint mailing list

Источник

How to Start, Stop, and Restart PostgreSQL in Linux

Start Stop Restart PostgreSQL

This short tutorial will show you how to start, stop, and restart PostgreSQL servers on your Linux system.

PostgreSQL is a flexible database system that allows you to run multiple versions of the server software on the same host. This can get a bit confusing, but thankfully PostgreSQL includes all of the tools you need to make sense of things and control each server individually.

How to Start PostgreSQL Service/Server

To start the default or primary PostgreSQL server on your system, simply run the following command:

systemctl start postgresql

The above command should work on all major Linux distributions.

How to Stop PostgreSQL Service/Server

To stop the default or primary PostgreSQL server on your system, simply run the following command:

sudo systemctl stop postgresql

The above command should work on all major Linux distributions.

How to Restart PostgreSQL Service/Server

To restart the default or primary PostgreSQL server on your system, simply run the following command:

sudo systemctl restart postgresql

The above command should work on all major Linux distributions.

Starting/Stopping Individual Clusters

If you have several running PostgreSQL clusters on your system (for example, two versions as the result of an upgrade), you may want to control the state of each cluster individually.

First, list the installed clusters by running the pg_lsclusters command:

The output should look something like this:

Ver Cluster Port Status Owner Data directory Log file 9.1 main 5433 online postgres /var/lib/postgresql/9.1/main /var/log/postgresql/postgresql-9.1-main.log 11 main 5432 online postgres /var/lib/postgresql/11/main /var/log/postgresql/postgresql-11-main.log

The state of each cluster can then be controlled using the below commands:

sudo pg_ctlcluster VERSIONNUMBER stop sudo pg_ctlcluster VERSIONNUMBER start

How to Start the PostgreSQL Service/Server Automatically on Boot

You can also enable or disable the automatic starting of the PostgreSQL server when your computer boots by running one of the following commands:

systemctl enable postgresql systemctl disable postgresql

If you’re new to PostgreSQL, check out our ever-evolving guide for developers here.

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.

Источник

Читайте также:  Debian linux vmware workstation
Оцените статью
Adblock
detector