dobyek
dobyek

Reputation: 139

postgreSQL is shut down but pg_checksums still says clusters must be shut down

My postgreSQL database has been corrupted so that I'm trying to fix it with pg_checksum.

I'm using docker with docker-compose,
and docker-compose.yml seems like below.

services:
  db:
    image: postgres
    volumes:
      - /home/AAA/BBB/data:/var/lib/postgresql/data
    environment:
      - POSTGRES_DB=AAAA
      - POSTGRES_USER=BBBB
      - POSTGRES_PASSWORD=CCCC
      - POSTGRES_INITDB_ARGS=--encoding=UTF-8

And the postgresql version is:

root@2c0d76d14318:/# postgres --version
postgres (PostgreSQL) 13.1 (Debian 13.1-1.pgdg100+1)

But when I tried the command pg_checksums -D /var/lib/postgresql/data --enable --progress --verbose - which is shown in https://postgreshelp.com/postgresql-checksum/ - in docker container, it emits an error like this:

root@2c0d76d14318:/# pg_checksums -D /var/lib/postgresql/data --enable --progress --verbose
pg_checksums: error: cluster must be shut down

So, I tried to shut down the postgres server by service postgresql stop but it also makes the error below:

root@2c0d76d14318:/# service postgresql stop
[warn] No PostgreSQL clusters exist; see "man pg_createcluster" ... (warning).

And the same if I tried pg_checksums again.

I'm really in hurry to solve this problem but have no idea about it.

Can somebody help to resolve this?

P.S. Welcome for fixing some syntactic problems. Sorry, I'm not an English speaker so that some phrases could be weird. Thank you in advance.

Upvotes: 0

Views: 1912

Answers (1)

jjanes
jjanes

Reputation: 44137

You enable pg_checksums before you have corruption, not after.

It needs the cluster to be shut down cleanly, and apparently it wasn't. It can't distinguish between a running server and a crashed (uncleanly shutdown) server. You could fix this just starting the cluster, letting go through automatic recovery, then shutting it down cleanly. But if it is already corrupt, this probably won't work. Whatever you need to do, pg_checksums is probably not the tool to do it.

Upvotes: 1

Related Questions