source

Postgres - FATAL: 데이터베이스 파일이 서버와 호환되지 않습니다.

ittop 2023. 6. 1. 22:56
반응형

Postgres - FATAL: 데이터베이스 파일이 서버와 호환되지 않습니다.

MacBook Pro를 다시 시작한 후 데이터베이스 서버를 시작할 수 없습니다.

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"?

로그를 확인했더니 다음 행이 반복적으로 나타납니다.

FATAL:  database files are incompatible with server
DETAIL:  The data directory was initialized by PostgreSQL version 9.2, which is not compatible with this version 9.0.4.

9.0.4는 Mac에 사전 설치된 버전이고 9.2[.4]는 Homebrew를 통해 설치한 버전입니다.

언급했듯이, 이것은 다시 시작하기 전에 작동했기 때문에 실제로 컴파일 문제가 될 수 없습니다.저도 다시 뛰었습니다.initdb /usr/local/var/postgres -E utf8파일은 여전히 존재합니다.

최근에 postgres를 최신 버전으로 업그레이드한 경우 다음 명령을 실행하여 모든 데이터가 저장된 postgres 데이터 디렉토리를 업그레이드할 수 있습니다.

brew postgresql-upgrade-database

위의 명령은 다음의 출력에서 가져옵니다.brew info postgres

참고: 최근 테스트 기준으로 14개에서 15개로 업그레이드하는 경우에는 작동하지 않습니다.

핵 옵션(모든 데이터 삭제 및 새 데이터베이스 가져오기)을 찾고 있는 경우 다음 작업을 수행할 수 있습니다.

rm -rf /usr/local/var/postgres && initdb /usr/local/var/postgres -E utf8

그리고 나서 당신은 할 필요가 있을 것입니다.rake db:setup그리고.rake db:migrateRails 앱에서 다시 설정합니다.

사용해 보십시오. https://gist.github.com/joho/3735740

그것은 저에게 완벽하게 효과가 있었습니다.마지막으로 DB를 확인하고 이전 클러스터를 제거하기 위한 2개의 bash 스크립트도 생성합니다.진짜 대박.

자세한 내용은 http://www.postgresql.org/docs/9.2/static/pgupgrade.html 을 참조하십시오.

인터넷에서 발견된 이 솔루션은 저에게 잘 작동합니다.

OS X 10.10 Yosemite로 업그레이드한 후 postgresql 서버를 시작하려고 할 때 다음 문제가 발생했습니다.

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

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

좋습니다. 서버 로그를 살펴보겠습니다.

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

FATAL: database files are incompatible with server
DETAIL: The data directory was initialized by PostgreSQL version 9.2, which is not compatible with this version 9.3.5.

따라서 postgresql을 업그레이드한 후 몇 가지 단계를 따라야 합니다.

launchctl unload -w ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist

mv /usr/local/var/postgres /usr/local/var/postgres92

brew update

brew upgrade postgresql

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

pg_upgrade -b /usr/local/Cellar/postgresql/9.2.3/bin -B /usr/local/Cellar/postgresql/9.3.5_1/bin -d /usr/local/var/postgres92 -D /usr/local/var/postgres

cp /usr/local/Cellar/postgresql/9.3.5_1/homebrew.mxcl.postgresql.plist ~/Library/LaunchAgents/

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

rm -rf /usr/local/var/postgres92

바로 그겁니다.

이전 버전의 postgres를 유지하려면 다음을 사용합니다.brew switch:

$ brew info postgresql

postgresql: stable 10.5 (bottled), HEAD
Object-relational database system
https://www.postgresql.org/
Conflicts with:
  postgres-xc (because postgresql and postgres-xc install the same binaries.)
/usr/local/Cellar/postgresql/9.6.3 (3,259 files, 36.6MB)
  Poured from bottle on 2017-07-09 at 22:15:41
/usr/local/Cellar/postgresql/10.5 (1,705 files, 20.8MB) *
  Poured from bottle on 2018-11-04 at 15:13:13

$ brew switch postgresql 9.6.3
$ brew services stop postgresql
$ brew services start postgresql

그렇지 않으면 다음 brew 명령을 사용하여 기존 데이터를 마이그레이션합니다.brew postgresql-upgrade-database소스 코드를 확인합니다.

@Gowtham이 언급했듯이 brew 명령을 실행하면 이 문제를 해결할 수 있습니다.

brew postgresql-upgrade-database위의 명령은 다음의 출력에서 가져옵니다.brew info postgres

그러나 실행하기 전에 postgres 서비스를 중지하는 것을 잊지 마십시오. 'brew services stop postgresql

서비스를 다시 시작해야 할 수도 있습니다.

명령의 마지막 순서는 다음과 같습니다.

brew services stop postgresql
brew postgresql-upgrade-database
brew services start postgresql  

이러한 답변(1, 2)과 마찬가지로, 다음으로 업그레이드한 후 내 Postgres 데이터베이스 파일이 내 Postgres 버전과 호환되지 않았습니다.postgresql 13.3.

안타깝게도 Postgres 데이터 디렉토리를 업그레이드하지 못했습니다.

$ brew postgresql-upgrade-database
...
Setting next OID for new cluster
*failure*

Consult the last few lines of "pg_upgrade_utility.log" for
the probable cause of the failure.
Failure, exiting
Error: Upgrading postgresql data from 12 to 13 failed!
==> Removing empty postgresql initdb database...
==> Moving postgresql data back from /usr/local/var/postgres.old to /usr/local/var/postgres...
Error: Failure while executing; `/usr/local/opt/postgresql/bin/pg_upgrade -r -b /usr/local/Cellar/postgresql@12/12.7/bin -B /usr/local/opt/postgresql/bin -d /usr/local/var/postgres.old -D /usr/local/var/postgres -j 8` exited with 1.

이 문제에 대한 해결 방법은 다시 설치하는 것이었습니다.postgresql 12.7.

$ brew reinstall postgresql@12
$ brew services start postgresql@12

도커에서 새 Postgres를 실행할 때 이전 볼륨이 업데이트되지 않을 때도 이 문제가 발생할 수 있습니다.

데이터를 보관할 필요가 없는 경우에는 다음과 같이 Linux에서 도커 폴더의 이전 볼륨을 지우는 것이 가장 쉽습니다.

/var/lib/docker/volumes

Postgres11 탑재 볼륨으로 Postgres12를 시작하려고 할 때 발생했습니다.postgres11의 마운트된 볼륨을 삭제하고 다시 시작하는 것만 해도 효과가 있었습니다.

이전에는 다음을 사용했습니다.

docker run -d --name my_database -v /Users/champ/postgres:/var/lib/postgresql/data -p 54320:5432 postgres:11

/Users/champ/postgres를 삭제하고 postgres 12를 다시 시작했습니다.

docker run -d --name my_database -v /Users/champ/postgres:/var/lib/postgresql/data -p 54320:5432 postgres:12

brew info postgres를 줄 예요.To migrate existing data from a previous major version of PostgreSQL run:

저 것을 예요.rm -rf /usr/local/var/postgres.old DB 를 수행합니다.brew postgresql-upgrade-database

postmaster.pid파일이 저를 위해 이것을 야기했습니다.

디렉토리 postgres로 ./Users/st/Library/Application Support/Postgres/나에게 그것은:

cd '/Users/<username>/Library/Application Support/Postgres/var-10'

그런 다음 파일을 삭제합니다.postmaster.pid를 다시 합니다.postgres는 이름입니다.

To me는 다음 명령으로 작동합니다.

brew install --build-from-source postgresql@12

그런 다음 Postgres를 시작했습니다.

brew services start postgresql@12

포트 5432가 수신 대기 상태인지 확인할 수도 있습니다.

netstat -nl |grep 5432

언급URL : https://stackoverflow.com/questions/17822974/postgres-fatal-database-files-are-incompatible-with-server

반응형