Postgresql restart mac os

TablePlus

How to start and stop PostgreSQL server?

October 30, 2018

In this post, we are going to figure out how to start, stop, and restart a PostgreSQL server on macOS, Linux, and Windows.

1. On macOS

If you installed PostgreSQL via Homebrew:

  • To start PostgreSQL server now and relaunch at login:

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:

  • Open Run Window by Winkey + R
  • Type services.msc
  • Search Postgres service based on version installed.
  • Click stop, start or restart the service option.

3. On Linux

Update and 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:

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.

Источник

PostgreSQL server won’t stop

Having a bit of an issue with PostgreSQL on Mac OS X 10.8.4. I accidentally did brew rm postgresql —force while the postgres server was running. When I installed using brew install postgresql and ran pg_ctl -D /usr/local/var/postgres start I get:

when I run «ps -ef | grep postgres» I get:

when I try to stop the server with pg_ctl stop -D /usr/local/var/postgres -m fast or pg_ctl -D /usr/local/var/postgres stop -mi I get:

EDIT

8 Answers 8

Had same issue, pg_ctl: server does not shut down . Furthermore, ps auxwww | grep postgres showed no postgres running, while pg_ctl -D /usr/local/var/postgres status showed that postgres is running. Restarting my mac didn’t help, i even went as far as to reset SMC, but this SO Q/A gave me an idea what to look for next: brew issues.

Following this line of thought, i found this helpful blog post, that came down to following commands that solved this issue for me:

Hope this will help someone.

Update — Unknown command: services

After a bit of investigation following one of the comments (‘Unknown command: services’), i found out that the authors of Homebrew decided to remove services from the repo, seeing as no one wants to maintain this code.

Читайте также:  Reset any windows password usb

You can read more about it here and here (related github tickets).

After some more digging, I found this repo that adds services on macs.

This is how I ‘returned’ services :

» brew tap gapple/services

» brew services usage: [sudo] brew services [—help] [

Источник

Stop postgreSQL service on Mac via terminal

Running postgreSQL 9.4.5_2 currently

Normally no news is good news but after I will run

and get pg_ctl: server is running (PID: 536)

I have also tried

Response message is:

I’ve also checked my /Library/LaunchDaemons/ to see why the service is starting at login but no luck so far. Anyone have any ideas on where I should check next? Force quit in the activity monitor also isn’t helping me any.

4 Answers 4

Tried sudo and su but no such luck. Just found this gui

If anyone can help with the terminal commands that would be very much appreciated, but till then the gui will get the job done.

I tried various options; finally, the below command worked.

you can stop the server using this command

Had the same issue, I had installed postgres locally and wanted to wrap in a docker container instead.

I solved it pretty radically by 1) uninstalling postgres 2) kill the leftover process on postgres port. If you don’t un-install the process restarts and grabs the port again — look at your Brewfile form brew bundle dump to check for a restart_service: true flag.

I reasoned that, as I am using containers, I should not need the local one anyway, but !! attention this will remove postgres from your system.

Note: if you still want to used psql you can brew install libpq , and add psql to your PATH (the command output shows you what to add to your .zshrc , or similar)

Источник

PostgreSQL not running on Mac

The error in its entirety reads:

psql: could not connect to server: No such file or directory. Is the server running locally and accepting connections on Unix domain socket «/tmp/.s.PGSQL.5432»?

This is my second time setting up Postgresql via Homebrew on my Mac, and I have no clue what is going on. Previously, it had been working. At some point, I must’ve entered a command that messed things up. I’m not sure. Now, whenever I enter a SQL command from the command line, I receive the above message. I’ve run a command to check whether the server is running, and it apparently is not. If I attempt to start the server using

I receive the following error:

postgres cannot access the server configuration file «/usr/local/pgsql/data/postgresql.conf»: No such file or directory

I’ve uninstalled and reinstalled Postgresql via Homebrew, but the problem persists. I’m completely at a loss as to how to get this working. Any help would be appreciated.

15 Answers 15

The problem can also be attributed to a crashed process that left postmaster.pid file behind.

I was getting the same

loop of Homebrew install / start / stop / restart to no avail.

Finally, brew postgresql-upgrade-database worked.

Seems I was on 9.6 instead of 10.4, and something my latest App Store restart restarted all my database servers.

Run this command to manually start the server:

I’ve just resolved the same problem. It’s just because I forgot to run it properly before use.

Читайте также:  Windows file and settings transfer

For pure installing postgresql on Mac OS, the process will be (using brew command):

then if you want to automatically run postgresql at login:

or else you just want to run it anytime you want:

If your case is more complicated, let’s brew uninstall postgresql and redo these steps.

I kept on getting the above error and none of the above solutions worked for me. Finally the following solution solved my problem on Mac OS X

Install postgres using brew

Install brew services

To start postgres as a background service

To stop postgres manually

We can also use brew services to restart Postgres

This happens when postgres server is not running. Steps to properly install Postgres via Homebrew on MAC :

brew install postgres

initdb /Users/ /db -E utf8 [This initializes postgres to use the given directory as the database directory. Normally it is not adviced to use the user directory for database storage. Edit sudoers file to add initdb and similar commands and then run initdb on /usr/local/var/postgres]

pg_ctl -D /Users/ /db -l logfile start [After getting success with step 2 it will prompt to run step 3. This command manually starts the server.]

I was looking for a long time, and this was the most clean and neat solution:

I recently upgraded Postgres from 9.2 to 9.3 using brew upgrade postgres. The process was smooth and pg_upgrade is a very handy tool.

However, trouble struck once I tried to run any specs that needed to connect to Postgres. Even though Postgres was definitely running, suddenly I was getting:

could not connect to server: No such file or directory (PG::ConnectionBad) Is the server running locally and accepting connections on Unix domain socket «/var/pgsql_socket/.s.PGSQL.5432»? The problem was that the new version of Postgres listens on /tmp/.s.PGSQL.5432 instead. I could’ve messed around with the config and made Postgres use the domain socket it was previously, or told Rails explictly how to connect, but both of those approaches seemed like work I shouldn’t have to do. At no point had I told Rails to connect to postgres on that path, Rails had assumed it, and now its assumptions were wrong.

The fix is simple, if a little suprising. When you install the ‘pg’ gem, it detects which version of Postgres is installed and sets the domain socket path appropriately. The solution is as simple as reinstalling the gem. $ gem uninstall pg $ cd my-rails-app/ $ bundle install

Источник

PostgreSQL Setup : Mac Edition

Reduce your efforts on PostgreSQL installation and issues in Mac OS with these 4 steps

PostgreSQL, also known as Postgres, is a free and open-source relational database management system emphasizing extensibility and technical standards compliance. It is designed to handle a range of workloads, from single machines to data warehouses or Web services with many concurrent users.

If you already have Homebrew installed, you can skip to Installing PostgreSQL. Otherwise, let’s keep going.

Step 1 : Getting Homebrew

To install PostgreSQL on the command line we will be using a package manager called Homebrew. In MacOSX 10.7 or higher, the Ruby interpreter comes pre-installed. Let’s start by copying and pasting the following command into our command line:

Step 2: Installing PostgreSQL

The first thing we’re going to do is install Postgres. There are two main ways to get Postgres onto your machine:

  1. Using a graphical installer like BigSQL or Postgres.app (Requires macOS 10.12 for latest)
  2. Using a package manager to install via the command line.
Читайте также:  Не работает редактор изображения windows

You can pick whichever option is right for you. For this tutorial, let’s see how to install on the command line.

How to check if PostgreSQL is installed in you mac?

Remove previous versions of PostgreSQL

Delete all Files of Postgres

Install Postgres with Homebrew

Start PostgreSQL server

To have launchd start postgresql now and restart at login:

Or, if you don’t want/need a background service you can just run:

Step 3: Initialize Database

If terminal shows an error like below:

Remove old database file

rm -r /usr/local/var/postgres

Run the initdb command again

Step 4.1: Connect to database via command line

Postgres works pretty hard to make itself usable right out of the box without you having to do anything. By default, it automatically creates the user postgres . Let’s see what other users it has created. Let’s start by using the psql utility, which is a utility installed with Postgres that lets you carry out administrative functions without needing to know their actual SQL commands.

Start by entering the following on the command line:

(You may need to use sudo psql postgres for this command to work, depending on how your system is configured).

17 Practical psql Commands That You Don’t Want To Miss

Summary: in this tutorial, we give you a list of common psql commands that helps you query data from PostgreSQL…

There are many clients for PostgreSQL on the Mac. You can find many of them in the Community Guide to PostgreSQL GUI Tools in the PostgreSQL wiki. Some of them are quite powerful; some are still a bit rough. Here’s a list of all the Mac Apps I found (in alphabetic order):

1. Postico

Postico is a modern Postgres client for OSX, built by the same developer who built Postgres.app (mentioned above). It is free, but you can buy a license to unlock additional power features. This is the GUI that I use to manage Postgres because it is built specifically for Mac and has a beautiful, very easy to use (but powerful) UI. It also includes an SQL editor for complex queries.

2. pgAdmin

pgAdmin is the oldest of the Postgres GUIs, its first version being released just a few months after Postgre’s first release in 1996. Having been rewritten several times, it can run on Linux, MacOSX, and Windows, and features powerful database management tools including a syntax-highlighted SQL editor. Designed to run on both client machines and on deployed servers, pgAdmin is capable of handling advanced cases that Postico cannot. It’s dashboard is one of it’s kind and is an absolute essential tool when using Postgres in a distributed microservice architecture.

3. DataGrip

DataGrip is my favorite when it comes to IDEs. It is a modern IDE developed by JetBrains that offers efficient schema navigation, an intelligent query console, and version control integration. DataGrip also resolves references in your SQL code and helps you refactor them.

Источник

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