Re: initdb / bootstrap design - Mailing list pgsql-hackers

From Andres Freund
Subject Re: initdb / bootstrap design
Date
Msg-id 20220220003152.qdnjp3skpkw42tof@alap3.anarazel.de
Whole thread Raw
In response to Re: initdb / bootstrap design  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: initdb / bootstrap design  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-hackers
Hi,

On 2022-02-19 18:35:18 -0500, Tom Lane wrote:
> Here's an initial patch that gets rid of the need for initdb to
> change the contents of postgres.bki before feeding it to the
> bootstrap backend.  After this, we could look at having the
> backend read the file directly.

Cool!

> I don't really detect any speed change from getting rid of initdb's
> string manipulations, but TBH I was not expecting any.  On my machine,
> that was lost in the noise already, according to perf(1).

Yea, I'd not expect much either. The slowdown around the string stuff that I
did see was on windows.

I would however expect some, but not huge, speedup by getting rid of the
line-by-line reading/writing of postgres.bki, even without moving the handling
to the backend.

A quick way to prototype the moving the handlign to the backend would be to
just call postgres with input redirection from postgres.bki...


> +    /*
> +     * Ideally we'd change the superuser name with ALTER USER, but the backend
> +     * will reject that with "session user cannot be renamed", so we must
> +     * cheat.  (In any case, we'd need a function to escape an identifier, not
> +     * a string literal.)  Likewise, we can't change template1's
> +     * locale/encoding without cheating.
> +     */
> +    static char *final_details[] = {
> +        "UPDATE pg_authid SET rolname = E'SUPERUSER_NAME' WHERE rolname = 'POSTGRES';\n\n",
> +        "UPDATE pg_database SET encoding = E'ENCODING', datcollate = E'LC_COLLATE', datctype = E'LC_CTYPE';\n\n",
> +        NULL
> +    };
> +
> +    detail_lines = replace_token(final_details, "SUPERUSER_NAME",
> +                                 escape_quotes(username));
> +    detail_lines = replace_token(detail_lines, "ENCODING",
> +                                 encodingid_to_string(encodingid));
> +    detail_lines = replace_token(detail_lines, "LC_COLLATE",
> +                                 escape_quotes(lc_collate));
> +    detail_lines = replace_token(detail_lines, "LC_CTYPE",
> +                                 escape_quotes(lc_ctype));

Hm, wouldn't it be less code to just use printf?

Greetings,

Andres Freund



pgsql-hackers by date:

Previous
From: Peter Geoghegan
Date:
Subject: Re: Removing more vacuumlazy.c special cases, relfrozenxid optimizations
Next
From: Tom Lane
Date:
Subject: Re: initdb / bootstrap design