sourcecode

Postgre를 시작하는 방법Mac OS X의 SQL 서버?

copyscript 2023. 6. 3. 08:39
반응형

Postgre를 시작하는 방법Mac OS X의 SQL 서버?

최종 업데이트:

나는 실행하는 것을 잊었습니다.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

이는 다음과 같은 문제를 제기합니다.

Postgre를 시작하는 방법SQL 서버?

업데이트:

> 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

그러나 Ruby on Rails 서버를 시작하려고 하면 다음과 같은 메시지가 나타납니다.

서버가 호스트 "localhost"에서 실행되고 포트 5432에서 TCP/IP 연결을 허용합니까?

업데이트 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

"서버가 실행 중입니까?" 메시지가 계속 표시됩니다.

Homebrew 패키지 관리자에는 자동으로 시작할 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)

정리중

PostgreSQL은 Homebrew, Fink, MacPorts 또는 Enterprise통해 설치되었을 가능성이 높습니다.DB 설치 관리자.

다음 명령의 출력을 확인하여 설치된 패키지 관리자를 확인합니다.

brew && brew list|grep postgres
fink && fink list|grep postgres
port && port installed|grep postgres

PostgreSQL(Homebrew를 통해 설치)을 수동으로 시작하고 중지하려면 가장 쉬운 방법은 다음과 같습니다.

brew services start postgresql

그리고.

brew services stop postgresql

특정 버전이 있는 경우 버전을 접미사로 지정해야 합니다.예:

brew services start postgresql@10

저도 거의 똑같은 문제가 있었는데, 당신은 initdb 명령을 수정 사항으로 언급했습니다.이것은 저에게도 해결책이었지만, 여기에 게시된 사람이 아무도 없었습니다. 그래서 그것을 찾고 있는 사람들을 위해:

initdb /usr/local/var/postgres -E utf8

컴퓨터가 갑자기 다시 시작된 경우


PG 서버를 시작하고 싶을 수도 있지만 시작하지 않았습니다.

./usr/local/var/postgres/postmaster.pid그런 다음 설치에 따라 언급된 여러 가지 방법 중 하나를 사용하여 서비스를 다시 시작할 수 있습니다.

있는지 할 수 : Postgres 로그상여확수있다습니인할을.tail -f /usr/local/var/postgres/server.log

특정 버전의 경우:-

 tail -f /usr/local/var/postgres@[VERSION_NUM]/server.log

Eg:

 tail -f /usr/local/var/postgres@11/server.log

다른 접근 방식은 런치 보석(launchctl의 포장지)을 사용하는 것입니다.

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

Postgre 시작하기SQL:

lunchy start postgres

Postgre를 중지하려면SQL:

lunchy stop postgres

자세한 내용은 "Postgre 설치 방법"을 참조하십시오.홈브루와 런치가 포함된 Mac에서의 SQL"

여기 제 2센트입니다.postgrespg_ctl의 별칭을 만들어 파일 .bash_profile(내 Postgre)에 넣었습니다.SQL 버전은 9.2.4이고 데이터베이스 경로는 /Library/PostgreSQL/9.2/data)입니다.

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

새 터미널을 시작합니다.

그리고 나서는요?Postgre를 시작/중지할 수 있습니다.다음을 포함하는 SQL 서버:

postgres.server start
postgres.server stop

Postgre를 시작/정지/재시작하는 가장 깨끗한 방법SQL을 설치한 경우brew설치와 함께 제공되는 시작 구성 파일을 간단히 언로드 및/또는 로드하는 것입니다.

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

첫 번째 줄은 Postgre를 중지합니다.SQL이 시작되고 두 번째 줄이 시작됩니다.모든 것이 파일에 있기 때문에 데이터 디렉토리 등을 지정할 필요가 없습니다.

Postgre 시작하기SQL 서버:

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

Postgre 종료하기SQL 서버:

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

CLI를 통해 별칭을 생성하여 다음 작업을 쉽게 수행할 수도 있습니다.

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'

이것으로 "pg-start"를 입력하여 Postgre를 시작할 수 있습니다.SQL 및 "pg-stop"을 사용하여 종료합니다.

테스트 목적으로, 나는 Postgre가SQL App이 최고의 옵션입니다!

앱을 실행하면 서버가 실행 중입니다.

앱을 닫으면 서버가 다운됩니다.

http://postgresapp.com/

Homebrew를 사용하여 설치한 경우 다음 명령으로 충분합니다.

brew services restart postgresql

이것은 때때로 작동하지 않을 수 있습니다.이 경우 다음 두 가지 명령이 확실히 작동합니다.

rm /usr/local/var/postgres/postmaster.pid

pg_ctl -D /usr/local/var/postgres start
# 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 PostgreSQL server
$ postgres -D /usr/local/var/postgres

# Create your database
$ createdb mydb

# Access the database
$ psql mydb
psql (9.0.1)
Type "help" for help.

때때로 그것은 당신이 놓치고 있는 버전일 뿐이고, 당신은 불필요하게 머리를 긁고 있습니다.

특정 버전의 Postgre를 사용하는 경우SQL(예: Postgre)SQL 10을 사용한 후 간단히 수행

brew services start postgresql@10

brew services stop postgresql@10

정상적인brew services start postgresql홈브루의 특정 버전에 대해 설치한 경우 버전이 없으면 작동하지 않습니다.

Postgre 설치 시Homebrew를 사용한 SQL,

brew install postgres

출력이 끝나면 다음 방법으로 서버를 시작할 수 있습니다.

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

이것이 가장 좋은 방법이라고 생각합니다.

편의를 위해 .profile 파일에 별칭을 추가할 수 있습니다.

저도 같은 문제가 있어서 첫 번째 게시물부터 모든 업데이트를 수행했습니다.하지만 로그 파일을 확인한 후,

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

나는 진정한 원인을 봅니다.

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

이 디렉터리에 대한 사용 권한을 변경한 후

chmod 0700 /usr/local/var/postgres

포스트그레SQL 서버가 시작되었습니다.

로그 파일을 매번 확인합니다.

빠른 일회용 테스트 데이터베이스의 경우 서버를 전경에서 실행할 수 있습니다.

새 Postgre 초기화새 디렉터리의 SQL 데이터베이스:

mkdir db
initdb db -E utf8
createdb public

서버를 Ctrl포그라운드에서 시작합니다(+를 눌러 서버를 중지합니다).

postgres -d db

다른 셸 세션에서 서버에 연결

psql -d public

이 답변의 변형: 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

홈브루와 함께 설치하지 않고 Mac 패키지에서 직접 설치하지 않았다면 Postgre에 대해 효과가 있었습니다.기본 위치, 변수 등을 모두 사용하는 경우 SQL 12.

$ sudo su postgres
bash-3.2$ /Library/PostgreSQL/12/bin/pg_ctl -D /Library/PostgreSQL/12/data/ stop

PostgreSQL은 Mac OS X v10.8(Mountain Lion)의 App Store를 통해 제공되는 Server.app에 통합되어 있습니다.즉, 이미 구성되어 있으므로 시작한 후 사용자와 데이터베이스를 작성하기만 하면 됩니다.

팁: $PGDATA 등을 정의하는 것으로 시작하지 마십시오.파일 위치를 그대로 사용합니다.

/Library/Server/PostgreSQL/Config/org.postgresql.postgres 파일이 있습니다.플리스터

시작하기:

sudo serveradmin start postgres

프로세스가 다음 인수로 시작되었습니다.

/Applications/Server.app/Contents/ServerRoot/usr/bin/postgres_real -D/Library/Server/PostgreSQL/Data -clisten_clisten=127.0.0.1,:1 -clog_connections=on -clog_directory=/Logs/PostgrealSQL - clog_filename=PostgreSQL.log -clog_line_dll=%t -clog_lock_dll=on -clog_statement=ddl -clogging_dll=on -cunix_directory=/private/var/pgsql_dll -cunix_dll_dll_dll_dll_dlloggres -cunix_dll_dll_dll_missions=0770

할 수 있습니다.

sudo -u _postgres psql template1

또는 연결:

psql -h localhost -U _postgres postgres

데이터 디렉토리, 버전, 실행 상태 등을 찾을 수 있습니다.

sudo serveradmin fullstatus postgres

개발 목적을 위해 가장 간단한 방법 중 하나는 공식 사이트에서 Postgres.app을 설치하는 것입니다.Applications 폴더에서 시작/중지하거나 터미널에서 다음 명령을 사용할 수 있습니다.

# Start
open -a Postgres

# Stop
killall Postgres
killall postgres

이것은 저에게 효과가 있었습니다(macOS v10.13(High Sierra)).

sudo -u postgres /Library/PostgreSQL/9.6/bin/pg_ctl start -D /Library/PostgreSQL/9.6/data

아니면 먼저

cd /Library/PostgreSQL/9.6/bin/

Postgre를 설치한 경우엔터프라이즈를 사용한 SQL그렇다면 Kenial이 제안한 방법은 DB instra입니다.

sudo -u postgres pg_ctl -D /Library/PostgreSQL/{version}/data start
sudo -u postgres pg_ctl -D /Library/PostgreSQL/{version}/data stop

홈브루가 방법입니다!!

서비스를 시작하는 방법

brew services start postgresql

목록 표시하기

brew services list | grep postgres

서비스를 중지하려면:

brew services stop postgresql

Homebrew로 Postgres 서버를 설치하지 않았거나 .dmg 파일을 사용하여 설치하지 않은 경우 다음을 시도하십시오.

$ sudo su postgres
bash-3.2$ /Library/PostgreSQL/13/bin/pg_ctl -D /Library/PostgreSQL/13/data/ stop

MacPorts의 경우 load/unload 명령과 실행 중인 서버의 포트 이름만 사용하면 됩니다.

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

그래서 당신은 어디에 있는지 기억할 필요가 없습니다./Library/LaunchDaemons/org.macports.postgresql96.plist파일이 있습니다.

Postgres와 함께 homebrew이것이 제가 포스트그레스를 시작하고 로그를 보기 위해 포그라운드에 보관하기 위해 하는 일입니다.

/opt/homebrew/opt/postgresql/bin/postgres -D /opt/homebrew/var/postgres
  • brew: brew를 합니다.brew install postgresql "@" 를 할 수 있습니다.brew install postgresql@14
  • 시작: postgresql 파일:brew services start postgresql 버전 는또특 버전정전brew services start postgresql@14
  • postgresql: postgresql 파일:brew services stop postgresql

$ brew upgrade postgres

저를 위해 그것을.

물론, 그것은 당신의 Postgre를 업그레이드할 것입니다.SQL 버전 및 모든 종속성 업데이트/설치.

경고:당신의 Postgre를 알고 이 일을 하라.SQL 버전이 변경될 수 있습니다.저한테는 큰 문제가 아니었어요.

동일한 오류 메시지를 받음에도 불구하고 이전 답변 중 어느 것도 문제를 해결하지 못했습니다.

잠겨 있고 연결이 허용되지 않는 기존 postmaster.pid 파일을 삭제하여 인스턴스를 다시 백업하고 실행할 수 있었습니다.

이것은 크레이그 링거에게서 영감을 받아 매번 저에게 효과가 있었습니다.

brew install proctools
sudo pkill -u postgres

proctools에는 pkill이 포함됩니다.Homebrew가 없는 경우: https://brew.sh/

brew 서비스를 수행한 후 postgresql을 다시 시작합니다.

가장 효과적인 작업: brew services stop postgresql brew postgresql-upgrade-database brew services start postgresql

그런 다음 psql을 입력합니다.

psql: error: could connect to server: 다음 오류 이후에 실행됩니다.해당 파일 또는 디렉터리 없음 서버가 로컬에서 실행되고 UNIX 도메인 소켓 "/tmp/.s"에서 연결을 허용합니다.PGSQL.5432"?

업그레이드는 실행 중인 다른 종속성에 따라 선택 사항일 수 있습니다.

즉, Macos에서 Brew for in을 사용하여 재시작하는 대신 완전히 postgres를 중지한 다음 postgres를 시작하고 psql databaseName에 연결합니다.

이것이 유용했기를 바랍니다.

언급URL : https://stackoverflow.com/questions/7975556/how-can-i-start-postgresql-server-on-mac-os-x

반응형