Jak uruchomić serwer PostgreSQL na Mac OS X?

OSTATNIA AKTUALIZACJA:

Zapomniałem uruchomić komendę initdb.

Uruchamiając to polecenie

ps auxwww | grep postgres

Widzę, że postgres nie działa

> ps auxwww | grep postgres
remcat          1789   0.0  0.0  2434892    480 s000  R+   11:28PM   0:00.00 grep postgres

Nasuwa się pytanie: Jak uruchomić serwer postgresql?

Aktualizacja:

>pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start
server starting
sh: /usr/local/var/postgres/server.log: No such file or directory

Update 2:

Dotyk nie powiódł się, więc zrobiłem to zamiast tego:

> mkdir /usr/local/var/postgres
> vi /usr/local/var/postgres/server.log
> ls /usr/local/var/postgres/          
server.log

Ale kiedy próbuję uruchomić rails server, wciąż widzę to:

Is the server running on host "localhost" and accepting
TCP/IP connections on port 5432?

Update 3:

> pg_ctl -D /usr/local/var/postgres status
pg_ctl: no server running

Update 4:

Stwierdziłem, że nie ma pg_hba.conf (tylko pg_hba.conf.próbka) więc zmodyfikowałem próbkę i przemianowałem ją (aby usunąć .próbka). Oto treść:

 # IPv4 local connections:
 host    all             all             127.0.0.1/32           trust
 # IPv6 local connections:
 host    all             all             ::1/128                trust

Ale tego nie rozumiem:

> pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start     
server starting
> pg_ctl -D /usr/local/var/postgres status                                     
pg_ctl: no server running

Także:

sudo find / -name postgresql.conf
find: /dev/fd/3: Not a directory
find: /dev/fd/4: Not a directory

Update 5:

sudo pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start
Password:
pg_ctl: cannot be run as root
Please log in (using, e.g., "su") as the (unprivileged) user that will own the server process.

Update 6:

To wydaje się dziwne:

> egrep 'listen|port' /usr/local/var/postgres/postgresql.conf
egrep: /usr/local/var/postgres/postgresql.conf: No such file or directory

Chociaż zrobiłem to:

>sudo find / -name "*postgresql.conf*"
find: /dev/fd/3: Not a directory
find: /dev/fd/4: Not a directory
/usr/local/Cellar/postgresql/9.0.4/share/postgresql/postgresql.conf.sample
/usr/share/postgresql/postgresql.conf.sample

Więc zrobiłem to:

egrep 'listen|port' /usr/local/Cellar/postgresql/9.0.4/share/postgresql/postgresql.conf.sample 
#listen_addresses = 'localhost'     # what IP address(es) to listen on;
#port = 5432                # (change requires restart)
                # supported by the operating system:
                #   %r = remote host and port

Więc próbowałem tego:

> cp /usr/local/Cellar/postgresql/9.0.4/share/postgresql/postgresql.conf.sample /usr/local/Cellar/postgresql/9.0.4/share/postgresql/postgresql.conf        
> cp /usr/share/postgresql/postgresql.conf.sample /usr/share/postgresql/postgresql.conf 

Still getting the same " czy serwer działa?"wiadomość.

Author: Ramy, 2011-11-02

20 answers

Menedżer pakietów Homebrew zawiera plisty launchctl, które uruchamiają się automatycznie. Aby uzyskać więcej informacji, Uruchom brew info postgres.

Uruchom ręcznie:

pg_ctl -D /usr/local/var/postgres start

Zatrzymaj ręcznie:

pg_ctl -D /usr/local/var/postgres stop

Uruchom automatycznie:

"aby launchd uruchomił postgresql teraz i zrestartował przy logowaniu:"

brew services start postgresql


Jaki jest wynik pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start?

Jaki jest wynik pg_ctl -D /usr/local/var/postgres status?

Czy są jakieś komunikaty o błędach na serwerze.log?

Upewnij się, że połączenia TCP localhost są włączone w pg_hba.conf:

# IPv4 local connections:
host    all             all             127.0.0.1/32            trust

Sprawdź listen_addresses i port w postgresql.conf:

egrep 'listen|port' /usr/local/var/postgres/postgresql.conf

#listen_addresses = 'localhost'     # what IP address(es) to listen on;
#port = 5432                # (change requires restart)

Sprzątanie

Postgres został najprawdopodobniej zainstalowany przez Homebrew, Fink, MacPorts lub instalator EnterpriseDB .

Sprawdź wyjście następujących poleceń aby określić, z którym menedżerem pakietów został zainstalowany:

brew && brew list|grep postgres
fink && fink list|grep postgres
port && port installed|grep postgres
 1483
Author: jamesallman,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2017-12-04 17:28:40

Jeśli chcesz ręcznie uruchomić i zatrzymać postgresql (zainstalowany przez homebrew), najprostszym sposobem jest:

brew services start postgresql

I

brew services stop postgresql
 280
Author: malopezcruz,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2014-06-16 20:18:09

Miałem prawie dokładnie ten sam problem, a Ty podałeś polecenie initdb jako poprawkę. To było również rozwiązanie dla mnie, ale nie widziałem, żeby ktoś go tu umieścił, więc dla tych, którzy go szukają: {]}

initdb /usr/local/var/postgres -E utf8
 168
Author: Yan,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2012-10-27 19:49:28

Inne podejście to lunchy gem (opakowanie dla launchctl):

brew install postgresql
initdb /usr/local/var/postgres -E utf8
gem install lunchy

Aby rozpocząć postgres:

lunchy start postgres

Aby zatrzymać postgres:

lunchy stop postgres

Aby uzyskać więcej informacji, zobacz: "Jak zainstalować PostgreSQL na Macu z Homebrew i Lunchy"

 78
Author: pisaruk,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2017-11-23 18:01:47

Tutaj Moje 2 grosze: zrobiłem alias dla Postgres pg_ctl i wrzuciłem .bash_profile (moja wersja postgresql to 9.2.4, a ścieżka do bazy danych to / Library / PostgreSQL / 9.2 / data).

alias postgres.server="sudo -u postgres pg_ctl -D /Library/PostgreSQL/9.2/data"

Uruchom nowy terminal.

A potem? Możesz uruchomić/zatrzymać serwer postgresql za pomocą tego:
postgres.server start
postgres.server stop
 69
Author: Kenial,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2016-04-02 19:00:33

Jeśli komputer został nagle uruchomiony ponownie

Najpierw musisz usunąć plik /usr/local/var/postgres/postmaster.pid, a następnie możesz ponownie uruchomić usługę za pomocą jednej z wielu innych wymienionych metod w zależności od instalacji.

Możesz to zweryfikować, przeglądając dzienniki Postgres, aby zobaczyć, co może się dziać: tail -f /usr/local/var/postgres/server.log
 64
Author: rafaelportela,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2017-04-14 16:12:17

Najczystszym sposobem zdecydowanie aby uruchomić/zatrzymać/ponownie uruchomić postgres, jeśli został on zainstalowany przez brew, jest po prostu rozładowanie i / lub załadowanie pliku konfiguracyjnego launchd dołączonego do instalacji:

launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist

Pierwsza linia zatrzyma postgres, a druga ją uruchomi. Nie ma potrzeby podawania żadnych katalogów danych itp. skoro wszystko jest w tych aktach.

 33
Author: Markus Amalthea Magnuson,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2015-05-20 11:49:31

Aby uruchomić serwer postgresql:

pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start

Aby zakończyć serwer postgresql:

pg_ctl -D /usr/local/var/postgres stop -s -m fast

Możesz również utworzyć alias za pomocą CLI, aby to ułatwić:

alias pg-start='pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start'
alias pg-stop='pg_ctl -D /usr/local/var/postgres stop -s -m fast'

Z nimi możesz po prostu wpisać "PG-start", aby uruchomić Postgres i" PG-stop", aby go wyłączyć.

 27
Author: Todd,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2013-06-27 13:55:13

Dla celów testowych, myślę, że aplikacja PostgreSQL jest najlepszym rozwiązaniem!

Uruchom aplikację, a serwer jest uruchomiony. Zamknij aplikację, a serwer zostanie wyłączony.

Http://postgresapp.com/

 21
Author: Crystian Leão,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2013-04-10 20:12:34

Kiedy instalujesz postgresql używając homebrew:

brew install postgres

Na końcu wyjścia zobaczysz następujące metody uruchamiania serwera:

To have launchd start postgresql at login:
    ln -sfv /usr/local/opt/postgresql/*.plist ~/Library/LaunchAgents
Then to load postgresql now:
    launchctl load ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
Or, if you don't want/need launchctl, you can just run:
    postgres -D /usr/local/var/postgres
Myślę, że to najlepszy sposób.

Możesz dodać alias do swojego .profil dla wygody.

 9
Author: jkaluzka,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2014-05-13 10:23:29

Dla szybkiej bazy testowej można uruchomić serwer na pierwszym planie.

Zainicjalizuj nową bazę danych postgres w nowym katalogu

mkdir db
initdb db -E utf8
createdb public

Uruchom serwer na pierwszym planie (ctrl-C, aby zatrzymać Serwer)

postgres -d db

W innej sesji powłoki, połącz się z serwerem

psql -d public
 7
Author: k107,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2015-05-07 16:38:16

Mam ten sam problem i wykonuję wszystkie aktualizacje od pierwszego posta. Ale po sprawdzeniu pliku dziennika:

/usr/local/var/postgres/server.log

Widzę prawdziwą przyczynę:

FATAL:  data directory "/usr/local/var/postgres" has group or world access
DETAIL:  Permissions should be u=rwx (0700).

Po zmianie uprawnień w tym katalogu

chmod 0700 /usr/local/var/postgres

Serwer Postgres uruchomiony.

Everytime check log file.

 7
Author: Roosh,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2016-03-09 08:39:35

Dla celów programistycznych, jednym z najprostszych sposobów jest instalacja Postgres.aplikacja z oficjalnej strony . Można go uruchomić/zatrzymać z folderu Applications lub używając następujących poleceń w terminalu:

# start
open -a Postgres

# stop
killall Postgres
killall postgres
 4
Author: Melnosta,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2013-10-20 20:29:42

PostgreSQL jest zintegrowany z serwerem .aplikacja dostępna w App Store w Mountain Lion. Oznacza to, że jest już skonfigurowany i wystarczy go uruchomić, a następnie utworzyć użytkowników i bazy danych.

Wskazówka: nie zaczynaj od definiowania $PGDATA i tak dalej, przyjmuj Lokalizacje plików tak, jak jest.

Będziesz miał ten plik: / Library / Server/PostgreSQL/Config / org.postgresql.postgres.plist

Na początek:

sudo serveradmin start postgres

Proces rozpoczął się od argumenty:

/Aplikacje / Serwer.app / Contents / ServerRoot / usr / bin / postgres_real-D/Library/Server/PostgreSQL/Data-C listen_addresses=127.0.0.1,::1-C log_connections=on-C log_directory=/Library/Logs / PostgreSQL-c log_filename=PostgreSQL.log -C log_line_prefix=%t-c log_lock_waits=on-C log_statement=ddl-C logging_collector=on-C unix_socket_directory=/private/var/pgsql_socket-C unix_socket_group=_postgres-C unix_socket_permissions=0770

Możesz sudo:

sudo -u _postgres psql template1

Lub Połącz:

psql -h localhost -U _postgres postgres

Możesz znaleźć katalog danych, wersję, stan pracy i tak dalej za pomocą

sudo serveradmin fullstatus postgres  
 4
Author: datasmid,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2013-11-24 00:58:26

Wariacja na temat tej odpowiedzi: https://stackoverflow.com/a/13103603/2394728

initdb `brew --prefix`/var/postgres/data -E utf8`
 4
Author: substancejoy,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2017-05-23 12:34:45

Żadna z powyższych odpowiedzi nie naprawiła problemu, pomimo otrzymania tych samych komunikatów o błędach. Udało mi się przywrócić i uruchomić moją instancję, usuwając istniejącego postmastera.plik pid, który był zablokowany i nie pozwalał na połączenia.

 1
Author: Swedendrift,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2017-01-04 10:03:17
   # remove old database files (If there was any)
   $rm -rf /usr/local/var/postgres    # install the binary

    $ brew install postgresql

    # init it
    $ initdb /usr/local/var/postgres

    # start the postgres server
    $ postgres -D /usr/local/var/postgres

    # create your database
    $ createdb mydb


    # Access db.
    $ psql mydb
    psql (9.0.1)
    Type "help" for help.
 1
Author: zee,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2018-01-21 23:41:49

Dla Mac / OSX, bardzo lubię LaunchRocket dla tego i innych usług w tle, z których korzystałem w rozwoju.

Https://github.com/jimbojsb/launchrocket

Ta strona ma ładne instrukcje dotyczące instalacji: http://macappstore.org/launchrocket/

To daje ładny ekran w Preferencjach systemowych, który pozwala na uruchomienie, restart, root, uruchomienie przy logowaniu.

 0
Author: theUtherSide,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2016-10-20 02:38:50

$ brew upgrade postgres

Naprawiłem to dla mnie.

To oczywiście zaktualizuje twoją wersję postgres i zaktualizuje / zainstaluje wszelkie zależności. Ostrzeżenie: zrób to wiedząc, że Twoja wersja postgresql prawdopodobnie się zmieni.Dla mnie to nic wielkiego.

 0
Author: thedanotto,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2016-12-29 18:43:20

Dla macports wystarczy użyć polecenia load/unload i nazwy portu uruchomionego serwera:

sudo port load postgresql96-server
- or -
sudo port unload postgresql96-server

Więc nie musisz pamiętać, gdzie znajduje się plik /Library/LaunchDaemons/org.macports.postgresql96.plist

 0
Author: Steve,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2018-08-17 03:28:20