Re: move collation import to backend

From: Andres Freund <andres(at)anarazel(dot)de>
To: Peter Eisentraut <peter(dot)eisentraut(at)2ndquadrant(dot)com>
Cc: pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: move collation import to backend
Date: 2016-11-12 15:38:30
Message-ID: 20161112153830.hy4pbjcf4jbrbr6q@alap3.anarazel.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi,

On 2016-10-27 21:56:53 -0400, Peter Eisentraut wrote:
> Currently, initdb parses locale -a output to populate pg_collation. If
> additional collations are installed in the operating system, it is not
> possible to repeat this process, only by doing each step manually. So I
> propose to move this to a backend function that can be called
> separately, and have initdb call that. Running this logic in the
> backend instead of initdb also makes the code simpler. If we add other
> collation providers such as ICU, initdb doesn't need to know about that
> at all, because all the logic would be contained in the backend.

That generally sounds like a good idea. There's some questions imo:
E.g. what if previously present collations are now unavailable?

> I thought about making this a top-level command (IMPORT COLLATIONS ...
> ?) but decided against it for now, to keep it simple.

Seems ok to me.

>
> /*
> * Also forbid matching an any-encoding entry. This test of course is not
> * backed up by the unique index, but it's not a problem since we don't
> * support adding any-encoding entries after initdb.
> */

Note that this isn't true anymore...

> +
> +Datum pg_import_system_collations(PG_FUNCTION_ARGS);
> +
> +Datum
> +pg_import_system_collations(PG_FUNCTION_ARGS)
> +{

Uh?

> + bool if_not_exists = PG_GETARG_BOOL(0);
> + Oid nspid = PG_GETARG_OID(1);
> +
> + FILE *locale_a_handle;
> + char localebuf[NAMEDATALEN]; /* we assume ASCII so this is fine */
> + int count = 0;
> +
> + locale_a_handle = OpenPipeStream("locale -a", "r");
> + if (locale_a_handle == NULL)
> + ereport(ERROR,
> + (errcode_for_file_access(),
> + errmsg("could not execute command \"%s\": %m",
> + "locale -a")));

This function needs to have !superuser permissions revoked, which it
afaics currently hasn't.

Greetings,

Andres Freund

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Andres Freund 2016-11-12 16:09:49 Re: Proposal for changes to recovery.conf API
Previous Message Andres Freund 2016-11-12 15:28:38 Re: Pinning a buffer in TupleTableSlot is unnecessary