/usr/lib/postgresql/17/bin/initdb: invalid option -- 'p'
Setup:
Moving from image: pgvector/pgvector:0.7.0-pg16 to pgautoupgrade/pgautoupgrade:latest.
Log:
postgres_app-1 |
postgres_app-1 | PostgreSQL Database directory appears to contain a database; Skipping initialization
postgres_app-1 |
postgres_app-1 | ************************************
postgres_app-1 | PostgreSQL data directory: /var/lib/postgresql/data
postgres_app-1 | ************************************
postgres_app-1 | *******************************************************************************************
postgres_app-1 | Performing PG upgrade on version 16 database files. Upgrading to version 17.5
postgres_app-1 | *******************************************************************************************
postgres_app-1 | ----------------------------------------------------------------------
postgres_app-1 | Checking for left over artifacts from a failed previous autoupgrade...
postgres_app-1 | ----------------------------------------------------------------------
postgres_app-1 | -------------------------------------------------------------------------------
postgres_app-1 | No artifacts found from a failed previous autoupgrade. Continuing the process.
postgres_app-1 | -------------------------------------------------------------------------------
postgres_app-1 | Creating upgrade lock file at /var/lib/postgresql/data/upgrade_in_progress.lock
postgres_app-1 | ---------------------------------------
postgres_app-1 | Creating OLD temporary directory /var/lib/postgresql/data/old
postgres_app-1 | ---------------------------------------
postgres_app-1 | --------------------------------------------
postgres_app-1 | Creating OLD temporary directory is complete
postgres_app-1 | --------------------------------------------
postgres_app-1 | -------------------------------------------------------
postgres_app-1 | Moving existing data files into OLD temporary directory
postgres_app-1 | -------------------------------------------------------
postgres_app-1 | renamed '/var/lib/postgresql/data/base' -> '/var/lib/postgresql/data/old/base'
postgres_app-1 | renamed '/var/lib/postgresql/data/global' -> '/var/lib/postgresql/data/old/global'
postgres_app-1 | mv: cannot move '/var/lib/postgresql/data/old' to a subdirectory of itself, '/var/lib/postgresql/data/old/old'
postgres_app-1 | renamed '/var/lib/postgresql/data/pg_commit_ts' -> '/var/lib/postgresql/data/old/pg_commit_ts'
postgres_app-1 | renamed '/var/lib/postgresql/data/pg_dynshmem' -> '/var/lib/postgresql/data/old/pg_dynshmem'
postgres_app-1 | renamed '/var/lib/postgresql/data/pg_hba.conf' -> '/var/lib/postgresql/data/old/pg_hba.conf'
postgres_app-1 | renamed '/var/lib/postgresql/data/pg_ident.conf' -> '/var/lib/postgresql/data/old/pg_ident.conf'
postgres_app-1 | renamed '/var/lib/postgresql/data/pg_logical' -> '/var/lib/postgresql/data/old/pg_logical'
postgres_app-1 | renamed '/var/lib/postgresql/data/pg_multixact' -> '/var/lib/postgresql/data/old/pg_multixact'
postgres_app-1 | renamed '/var/lib/postgresql/data/pg_notify' -> '/var/lib/postgresql/data/old/pg_notify'
postgres_app-1 | renamed '/var/lib/postgresql/data/pg_replslot' -> '/var/lib/postgresql/data/old/pg_replslot'
postgres_app-1 | renamed '/var/lib/postgresql/data/pg_serial' -> '/var/lib/postgresql/data/old/pg_serial'
postgres_app-1 | renamed '/var/lib/postgresql/data/pg_snapshots' -> '/var/lib/postgresql/data/old/pg_snapshots'
postgres_app-1 | renamed '/var/lib/postgresql/data/pg_stat' -> '/var/lib/postgresql/data/old/pg_stat'
postgres_app-1 | renamed '/var/lib/postgresql/data/pg_stat_tmp' -> '/var/lib/postgresql/data/old/pg_stat_tmp'
postgres_app-1 | renamed '/var/lib/postgresql/data/pg_subtrans' -> '/var/lib/postgresql/data/old/pg_subtrans'
postgres_app-1 | renamed '/var/lib/postgresql/data/pg_tblspc' -> '/var/lib/postgresql/data/old/pg_tblspc'
postgres_app-1 | renamed '/var/lib/postgresql/data/pg_twophase' -> '/var/lib/postgresql/data/old/pg_twophase'
postgres_app-1 | renamed '/var/lib/postgresql/data/PG_VERSION' -> '/var/lib/postgresql/data/old/PG_VERSION'
postgres_app-1 | renamed '/var/lib/postgresql/data/pg_wal' -> '/var/lib/postgresql/data/old/pg_wal'
postgres_app-1 | renamed '/var/lib/postgresql/data/pg_xact' -> '/var/lib/postgresql/data/old/pg_xact'
postgres_app-1 | renamed '/var/lib/postgresql/data/postgresql.auto.conf' -> '/var/lib/postgresql/data/old/postgresql.auto.conf'
postgres_app-1 | renamed '/var/lib/postgresql/data/postgresql.conf' -> '/var/lib/postgresql/data/old/postgresql.conf'
postgres_app-1 | renamed '/var/lib/postgresql/data/postmaster.opts' -> '/var/lib/postgresql/data/old/postmaster.opts'
postgres_app-1 | renamed '/var/lib/postgresql/data/upgrade_in_progress.lock' -> '/var/lib/postgresql/data/old/upgrade_in_progress.lock'
postgres_app-1 | -------------------------------------------------------------------
postgres_app-1 | Moving existing data files into OLD temporary directory is complete
postgres_app-1 | -------------------------------------------------------------------
postgres_app-1 | ---------------------------------------
postgres_app-1 | Creating NEW temporary directory /var/lib/postgresql/data/new
postgres_app-1 | ---------------------------------------
postgres_app-1 | --------------------------------------------
postgres_app-1 | Creating NEW temporary directory is complete
postgres_app-1 | --------------------------------------------
postgres_app-1 | -----------------------------------------------------
postgres_app-1 | Changing permissions of temporary directories to 0700
postgres_app-1 | -----------------------------------------------------
postgres_app-1 | ---------------------------------------------------------
postgres_app-1 | Changing permissions of temporary directories is complete
postgres_app-1 | ---------------------------------------------------------
postgres_app-1 | -------------------------------------------------
postgres_app-1 | Remove postmaster.pid file from PG data directory
postgres_app-1 | -------------------------------------------------
postgres_app-1 | ------------------------------------
postgres_app-1 | Determining our own initdb arguments
postgres_app-1 | ------------------------------------
postgres_app-1 | 2025-08-21 07:03:45.802 UTC [41] LOG: checkpoint starting: shutdown immediate
postgres_app-1 | 2025-08-21 07:03:45.869 UTC [41] LOG: checkpoint complete: wrote 2 buffers (0.0%); 0 WAL file(s) added, 0 removed, 0 recycled; write=0.027 s, sync=0.010 s, total=0.076 s; sync files=3, longest=0.004 s, average=0.004 s; distance=0 kB, estimate=0 kB; lsn=0/E4080FA0, redo lsn=0/E4080FA0
postgres_app-1 | ---------------------------------------------------------------
postgres_app-1 | The initdb arguments we determined are: --encoding=UTF8 -p 31102
postgres_app-1 | ---------------------------------------------------------------
postgres_app-1 | --------------------------------------------------------------------------------------------------------------------
postgres_app-1 | Old database using collation settings: '--encoding=UTF8 -p 31102'. Initialising new database with those settings too
postgres_app-1 | --------------------------------------------------------------------------------------------------------------------
postgres_app-1 | Initialising PostgreSQL 17.5 data directory
postgres_app-1 | /usr/lib/postgresql/17/bin/initdb: invalid option -- 'p'
postgres_app-1 | initdb: hint: Try "initdb --help" for more information.
postgres_app-1 exited with code 0
postgres_app-1 | The files belonging to this database system will be owned by user "postgres".
postgres_app-1 | This user must also own the server process.
postgres_app-1 |
postgres_app-1 | The database cluster will be initialized with locale "en_US.utf8".
postgres_app-1 | The default database encoding has accordingly been set to "UTF8".
postgres_app-1 | The default text search configuration will be set to "english".
postgres_app-1 |
postgres_app-1 | Data page checksums are disabled.
postgres_app-1 |
postgres_app-1 | initdb: error: directory "/var/lib/postgresql/data" exists but is not empty
postgres_app-1 | initdb: hint: If you want to create a new database system, either remove or empty the directory "/var/lib/postgresql/data" or run initdb with an argument other than "/var/lib/postgresql/data".
There are 2 errors that happen:
postgres_app-1 | mv: cannot move '/var/lib/postgresql/data/old' to a subdirectory of itself, '/var/lib/postgresql/data/old/old'
And later:
postgres_app-1 | Initialising PostgreSQL 17.5 data directory
postgres_app-1 | /usr/lib/postgresql/17/bin/initdb: invalid option -- 'p'
postgres_app-1 | initdb: hint: Try "initdb --help" for more information.
postgres_app-1 exited with code 0
The full docker compose:
version: "3.8"
name: app-dev
services:
postgres_app:
# image: pgautoupgrade/pgautoupgrade:latest
image: pgvector/pgvector:0.7.0-pg16
restart: always
command: -p 31102
environment:
POSTGRES_PASSWORD: ${DATABASE_PASSWORD:?}
POSTGRES_USER: app_dev
POSTGRES_DB: app_dev
expose:
- "31102"
ports:
- "31102:31102"
volumes:
- postgres-app-data:/var/lib/postgresql/data
shm_size: 4G
volumes:
postgres-app-data: {}
can you post your docker compose before and after the change to pgautoupgrade?
can you post your docker compose before and after the change to pgautoupgrade?
Sure, added it to the original post.
I would likely it is caused by #129. Your -p for changing the port gets forwarded to the initdb process, which does not know how to handle this. @spwoodcock do you have an elegant idea in mind how to strip away arguments that initdb might not know?
I am also not quite sure why you change the port of the actual Postgres instance inside the Docker instead of just adjusting your port mapping (31102:5432),
I would likely it is caused by #129. Your
-pfor changing the port gets forwarded to theinitdbprocess, which does not know how to handle this. @spwoodcock do you have an elegant idea in mind how to strip away arguments thatinitdbmight not know?I am also not quite sure why you change the port of the actual Postgres instance inside the Docker instead of just adjusting your port mapping (
31102:5432),
Ah yes, that is an unintended consequence I didn't consider 🤦♂️
But I was going to say exactly the same thing.
Adjusting the port isn't necessary here. Remove the command from the compose file, and instead update ports to:
- "31102:5432"
That should fix your problem 👍
[!NOTE] If other users also report the same using useful custom command params (they mostly match between
initdbandpostgres), then I'll dig into this and try to find a nice solution.Edit: saying that, perhaps a warning that is more user friendly explaining the issue could be a good start.