重新启动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上预装的版本。4]是我通过Homebrew安装的版本。
如前所述,这在重新启动之前是可以工作的,因此它实际上不可能是编译问题。我还重新运行了initdb /usr/local/var/postgres -E utf8,文件仍然存在。
如果你想保留之前的postgres版本,使用brew开关:
$ 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。查看源代码。
当我试图用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