Mac OS X에서 PostgreSQL 서버를 시작하는 방법은 무엇입니까?
최종 업데이트 :
나는 initdb
명령 을 실행하는 것을 잊었다 .
</ 최종 업데이트>
이 명령을 실행하여
ps auxwww | grep postgres
postgres가 실행되지 않는 것을 확인합니다.
> ps auxwww | grep postgres
remcat 1789 0.0 0.0 2434892 480 s000 R+ 11:28PM 0:00.00 grep postgres
이것은 질문을 제기합니다 : postgresql 서버를 어떻게 시작합니까?
최신 정보:
>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
업데이트 2 :
터치가 성공하지 못 했으므로 대신 이렇게했습니다.
> mkdir /usr/local/var/postgres
> vi /usr/local/var/postgres/server.log
> ls /usr/local/var/postgres/
server.log
그러나 레일스 서버를 시작하려고하면 여전히 다음과 같은 내용이 표시됩니다.
Is the server running on host "localhost" and accepting
TCP/IP connections on port 5432?
업데이트 3 :
> pg_ctl -D /usr/local/var/postgres status
pg_ctl: no server running
업데이트 4 :
pg_hba.conf (pg_hba.conf.sample 만 해당)가 없다는 것을 알았으므로 샘플을 수정하고 이름을 변경했습니다 (.sample 제거). 내용은 다음과 같습니다.
# IPv4 local connections:
host all all 127.0.0.1/32 trust
# IPv6 local connections:
host all all ::1/128 trust
그러나 나는 이것을 이해하지 못한다.
> 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
또한:
sudo find / -name postgresql.conf
find: /dev/fd/3: Not a directory
find: /dev/fd/4: Not a directory
업데이트 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.
업데이트 6 :
이상하게 보입니다.
> egrep 'listen|port' /usr/local/var/postgres/postgresql.conf
egrep: /usr/local/var/postgres/postgresql.conf: No such file or directory
그래도 이렇게했습니다.
>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
그래서 나는 이것을했다 :
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
그래서 나는 이것을 시도했다.
> 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
여전히 동일한 "서버가 실행 중입니까?" 메시지.
브루 패키지 관리자가 자동으로 시작 launchctl 속성 목록이 포함되어 있습니다. 자세한 내용은 brew info postgres
.
수동으로 시작 :
pg_ctl -D /usr/local/var/postgres start
수동으로 중지 :
pg_ctl -D /usr/local/var/postgres stop
자동으로 시작 :
"지금 postgresql을 시작하고 로그인 할 때 다시 시작하려면 :"
brew services start postgresql
결과는 pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start
무엇입니까?
결과는 pg_ctl -D /usr/local/var/postgres status
무엇입니까?
server.log에 오류 메시지가 있습니까?
pg_hba.conf에서 tcp localhost 연결이 활성화되어 있는지 확인하십시오.
# IPv4 local connections:
host all all 127.0.0.1/32 trust
postgresql.conf에서 listen_addresses 및 포트를 확인하십시오.
egrep 'listen|port' /usr/local/var/postgres/postgresql.conf
#listen_addresses = 'localhost' # what IP address(es) to listen on;
#port = 5432 # (change requires restart)
청소
Postgres는 Homebrew , Fink , MacPorts 또는 EnterpriseDB 설치 프로그램을 통해 설치되었을 가능성이 높습니다 .
다음 명령의 출력을 확인하여 설치된 패키지 관리자를 판별하십시오.
brew && brew list|grep postgres
fink && fink list|grep postgres
port && port installed|grep postgres
If you want to manually start and stop postgresql (installed via homebrew), the easiest way is:
brew services start postgresql
and
brew services stop postgresql
I had almost the exact same issue, and you cited the initdb command as being the fix. This was also the solution for me, but I didn't see that anyone posted it here, so for those who are looking for it:
initdb /usr/local/var/postgres -E utf8
If your computer was abruptly restarted
First, you have to delete the file /usr/local/var/postgres/postmaster.pid
Then you can restart the service using one of the many other mentioned methods depending on your install.
You can verify this by looking at the logs of Postgres to see what might be going on: tail -f /usr/local/var/postgres/server.log
Another approach is using lunchy gem (a wrapper for launchctl):
brew install postgresql
initdb /usr/local/var/postgres -E utf8
gem install lunchy
To start postgres:
lunchy start postgres
To stop postgres:
lunchy stop postgres
For further info refer to: "How to Install PostgreSQL on a Mac With Homebrew and Lunchy"
Here my 2 cents: I made an alias for postgres pg_ctl and put it in .bash_profile(my postgresql version is 9.2.4, and database path is /Library/PostgreSQL/9.2/data).
alias postgres.server="sudo -u postgres pg_ctl -D /Library/PostgreSQL/9.2/data"
Launch new terminal.
And then? You can start/stop your postgresql server with this:
postgres.server start
postgres.server stop
The cleanest way by far to start/stop/restart postgres if you have installed it through brew
is to simply unload and/or load the launchd configuration file that comes with the installation:
launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
The first line will stop postgres and the second line will start it. No need to specify any data directories etc. since everything is in that file.
To start the postgresql server:
pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start
to end the postgresql server:
pg_ctl -D /usr/local/var/postgres stop -s -m fast
You can also create an alias via CLI to make it easier:
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'
With these you can just type "pg-start" to start Postgres and "pg-stop" to shut it down.
For test purposes, i think PostgreSQL App is the best option!
Run an App, and the server is up and running. Close the App, and the server goes down.
when you install postgresql using homebrew:
brew install postgres
at the end of the output you will see this methods to start server:
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
I think this is the best way.
You can add alias into your .profile for convenience.
For a quick disposable test database you can run the server in the foreground.
Initialize a new postgres database in a new directory
mkdir db
initdb db -E utf8
createdb public
Start the server in the foreground (ctrl-C to stop the server)
postgres -d db
In another shell session, connect to the server
psql -d public
I have same problem and perform all updates from first post. But after check log file:
/usr/local/var/postgres/server.log
I see true cause:
FATAL: data directory "/usr/local/var/postgres" has group or world access
DETAIL: Permissions should be u=rwx (0700).
After change permission on this directory
chmod 0700 /usr/local/var/postgres
postgres server has start.
Everytime check log file.
Variation on this answer: https://stackoverflow.com/a/13103603/2394728
initdb `brew --prefix`/var/postgres/data -E utf8`` && pg_ctl -D /usr/local/var/postgres/data -l logfile start
For development purposes, one of the simplest ways is to install Postgres.app from the official site. It can be started/stopped from Applications folder or using the following commands in terminal:
# start
open -a Postgres
# stop
killall Postgres
killall postgres
PostgreSQL is integrated in Server.app available through the App Store in Mountain Lion. That means that it is already configured, and you only need to launch it, and then create users and databases.
Tip: Do not start with defining $PGDATA and so on, take file locations as is.
You would have this file: /Library/Server/PostgreSQL/Config/org.postgresql.postgres.plist
To start:
sudo serveradmin start postgres
Process started with arguments:
/Applications/Server.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
You can sudo:
sudo -u _postgres psql template1
Or connect:
psql -h localhost -U _postgres postgres
You can find the data directory, version, running status and so forth with
sudo serveradmin fullstatus postgres
# 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.
If you have installed using brew, below command should be enough.
brew services restart postgresql
And this sometimes might not work, in that case below two commands should definitely work
rm /usr/local/var/postgres/postmaster.pid
pg_ctl -D /usr/local/var/postgres start
$ brew upgrade postgres
fixed it for me.
That, of course, will upgrade your postgres version and update/install any dependencies. WARNING: Do this knowing that your postgresql version will likely change. For me, that wasn't a big deal.
none of the above answers fixed the issue for me despite getting the same error messages. I was able to get my instance back up and running by deleting the existing postmaster.pid file which was locked and not allowing connections.
For macports, just use the load/unload command and the port name of the running server:
sudo port load postgresql96-server
- or -
sudo port unload postgresql96-server
so you don't have to remember where the /Library/LaunchDaemons/org.macports.postgresql96.plist
file is located
docker run --name some-postgres -e POSTGRES_PASSWORD=mysecretpassword -d postgres
https://hub.docker.com/_/postgres
If you installed Postgres using EnterpriseDB installer then what @Kenial suggested is the way to go.
sudo -u postgres pg_ctl -D /Library/PostgreSQL/{version}/data start
sudo -u postgres pg_ctl -D /Library/PostgreSQL/{version}/data stop
For Mac/OSX, I really like LaunchRocket for this and other background services I used in development.
https://github.com/jimbojsb/launchrocket
This site has nice instructions on installation: http://macappstore.org/launchrocket/
This gives you a nice screen in your System Preferences that allows you to launch, reboot, root, launch at login.
This worked for me every time, inspired by Craig Ringer:
brew install proctools
sudo pkill -u postgres
proctools includes pkill. If you don't have Brew: https://brew.sh/
For completeness sake: Check whether you're inside a Tmux
or Screen
instance, starting won't work from there.
This solved it for me.
There is some edge case that maybe will be helpfull for someone:
There is option, that you will have postgres.pid filled with some PID. But if your restart your machine, and before postgress will be back again, some other process will take that PID. If that will happen, both pg_ctl status and brew service asked about postgres status, will tell you that it is UP. Just ps aux | grep and check if it is really postgress
that worked for me (macOS 10.13) sudo -u postgres /Library/PostgreSQL/9.6/bin/pg_ctl start -D /Library/PostgreSQL/9.6/data
or first cd /Library/PostgreSQL/9.6/bin/
참고URL : https://stackoverflow.com/questions/7975556/how-to-start-postgresql-server-on-mac-os-x
'developer tip' 카테고리의 다른 글
글로벌 Git 구성을 어떻게 표시합니까? (0) | 2020.09.28 |
---|---|
어떤 버전의 PostgreSQL을 실행하고 있습니까? (0) | 2020.09.28 |
파이썬에서 XML을 어떻게 구문 분석합니까? (0) | 2020.09.28 |
JavaScript로 어떻게 리디렉션합니까? (0) | 2020.09.28 |
동일한 기능을 트리거하는 jQuery 여러 이벤트 (0) | 2020.09.28 |