andrewvo148
andrewvo148

Reputation: 13

Error when init database postgresql 10.10: PANIC: could not generate secret authorization token

I have a problem when run command: sudo -su user_test ./pgsql/bin/initdb -D /example/folder
I had researched many sources from the internet but don’t found a solution. I hope everyone could help me. Thanks.

Enviroment:

selecting default max_connections … 100
selecting default shared_buffers … 128MB
selecting default timezone … Europe/Helsinki
selecting dynamic shared memory implementation … posix
creating configuration files … ok
running bootstrap script … 2020-11-03 11:52:56.303 EET [3928] DEBUG: invoking IpcMemoryCreate(size=148545536)
2020-11-03 11:52:56.303 EET [3928] DEBUG: mmap(148897792) with MAP_HUGETLB failed, huge pages disabled: Cannot allocate memory
2020-11-03 11:52:56.315 EET [3928] DEBUG: SlruScanDirectory invoking callback on pg_notify/0000
2020-11-03 11:52:56.315 EET [3928] DEBUG: removing file "pg_notify/0000"
2020-11-03 11:52:56.316 EET [3928] DEBUG: dynamic shared memory system will support 288 segments
2020-11-03 11:52:56.316 EET [3928] DEBUG: created dynamic shared memory control segment 1852866650 (6928 bytes)
2020-11-03 11:52:56.319 EET [3928] PANIC: could not generate secret authorization token
Aborted
child process exited with exit code 134```

Upvotes: 1

Views: 364

Answers (2)

andrewvo148
andrewvo148

Reputation: 13

It worked fine. Thank you very much, @Laurenz Albe

Upvotes: 0

Laurenz Albe
Laurenz Albe

Reputation: 248165

The error is thrown in BootStrapXLOG in src/backend/access/transam/xlog.c:

    /*
     * Generate a random nonce. This is used for authentication requests that
     * will fail because the user does not exist. The nonce is used to create
     * a genuine-looking password challenge for the non-existent user, in lieu
     * of an actual stored password.
     */
    if (!pg_backend_random(mock_auth_nonce, MOCK_AUTH_NONCE_LEN))
        ereport(PANIC,
                (errcode(ERRCODE_INTERNAL_ERROR),
                 errmsg("could not generate secret authorization token")));

src/backend/utils/misc/backend_random.c says:

pg_backend_random() function fills a buffer with random bytes. Normally,
it is just a thin wrapper around pg_strong_random(), but when compiled
with --disable-strong-random, we provide a built-in implementation.

So it seems that PostgreSQL was built on a system that had a source for strong random numbers (OpenSSL or /dev/urandom, if you are not on Windows), but the facility is not working on your current system.

  • try with the lates minor release of v10 (currently 10.15) – maybe a bug has been fixed.

  • run pg_config --configure to check if PostgreSQL was built --with-openssl

  • OpenSSL also uses /dev/urandom, so there is likely a problem with that source of random numbers; investigate there

If all fails, build PostgreSQL from source and configure it with

./configure --disable-strong-random ...

Upvotes: 1

Related Questions