public inbox for [email protected]help / color / mirror / Atom feed
[PATCH 3/4] demote: add pg_demote() function 5+ messages / 4 participants [nested] [flat]
* [PATCH 3/4] demote: add pg_demote() function @ 2020-07-31 16:07 Jehan-Guillaume de Rorthais <[email protected]> 0 siblings, 0 replies; 5+ messages in thread From: Jehan-Guillaume de Rorthais @ 2020-07-31 16:07 UTC (permalink / raw) --- src/backend/access/transam/xlogfuncs.c | 94 ++++++++++++++++++++++++++ src/backend/catalog/system_views.sql | 6 ++ src/include/catalog/pg_proc.dat | 4 ++ 3 files changed, 104 insertions(+) diff --git a/src/backend/access/transam/xlogfuncs.c b/src/backend/access/transam/xlogfuncs.c index 290658b22c..733f465d38 100644 --- a/src/backend/access/transam/xlogfuncs.c +++ b/src/backend/access/transam/xlogfuncs.c @@ -784,3 +784,97 @@ pg_promote(PG_FUNCTION_ARGS) (errmsg("server did not promote within %d seconds", wait_seconds))); PG_RETURN_BOOL(false); } + +/* + * Demotes a production server. + * + * A result of "true" means that demotion has been completed if "wait" is + * "true", or initiated if "wait" is false. + */ +Datum +pg_demote(PG_FUNCTION_ARGS) +{ + bool fast = PG_GETARG_BOOL(0); + bool wait = PG_GETARG_BOOL(1); + int wait_seconds = PG_GETARG_INT32(2); + char demote_filename[] = "demote_fast"; + FILE *demote_file; + int i; + + if (RecoveryInProgress()) + ereport(ERROR, + (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), + errmsg("recovery in progress"), + errhint("you can not demote while already in recovery."))); + + if (!EnableHotStandby) + ereport(ERROR, + (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), + errmsg("function pg_demote() requires hot_standby parameter to be enabled"), + errhint("The function can not return its status from a non hot_standby-enabled standby"))); + + if (wait_seconds <= 0) + ereport(ERROR, + (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE), + errmsg("\"wait_seconds\" must not be negative or zero"))); + + if (!fast) + demote_filename[6] = '\0'; + + /* create the demote signal file */ + demote_file = AllocateFile(demote_filename, "w"); + if (!demote_file) + ereport(ERROR, + (errcode_for_file_access(), + errmsg("could not create file \"%s\": %m", + demote_filename))); + + if (FreeFile(demote_file)) + ereport(ERROR, + (errcode_for_file_access(), + errmsg("could not write file \"%s\": %m", + demote_filename))); + + /* signal the postmaster */ + if (kill(PostmasterPid, SIGUSR1) != 0) + { + ereport(WARNING, + (errmsg("failed to send signal to postmaster: %m"))); + (void) unlink(demote_filename); + PG_RETURN_BOOL(false); + } + + /* return immediately if waiting was not requested */ + if (!wait) + PG_RETURN_BOOL(true); + + /* wait for the amount of time wanted until demotion */ +#define WAITS_PER_SECOND 10 + for (i = 0; i < WAITS_PER_SECOND * wait_seconds; i++) + { + int rc; + + ResetLatch(MyLatch); + + if (RecoveryInProgress()) + PG_RETURN_BOOL(true); + + CHECK_FOR_INTERRUPTS(); + + rc = WaitLatch(MyLatch, + WL_LATCH_SET | WL_TIMEOUT | WL_POSTMASTER_DEATH, + 1000L / WAITS_PER_SECOND, + WAIT_EVENT_DEMOTE); + + /* + * Emergency bailout if postmaster has died. This is to avoid the + * necessity for manual cleanup of all postmaster children. + */ + if (rc & WL_POSTMASTER_DEATH) + PG_RETURN_BOOL(false); + } + + ereport(WARNING, + (errmsg("server did not demote within %d seconds", wait_seconds))); + PG_RETURN_BOOL(false); +} diff --git a/src/backend/catalog/system_views.sql b/src/backend/catalog/system_views.sql index 8625cbeab6..573d7b46eb 100644 --- a/src/backend/catalog/system_views.sql +++ b/src/backend/catalog/system_views.sql @@ -1219,6 +1219,11 @@ CREATE OR REPLACE FUNCTION RETURNS boolean STRICT VOLATILE LANGUAGE INTERNAL AS 'pg_promote' PARALLEL SAFE; +CREATE OR REPLACE FUNCTION + pg_demote(fast boolean DEFAULT true, wait boolean DEFAULT true, wait_seconds integer DEFAULT 60) + RETURNS boolean STRICT VOLATILE LANGUAGE INTERNAL AS 'pg_demote' + PARALLEL SAFE; + -- legacy definition for compatibility with 9.3 CREATE OR REPLACE FUNCTION json_populate_record(base anyelement, from_json json, use_json_as_text boolean DEFAULT false) @@ -1435,6 +1440,7 @@ REVOKE EXECUTE ON FUNCTION pg_reload_conf() FROM public; REVOKE EXECUTE ON FUNCTION pg_current_logfile() FROM public; REVOKE EXECUTE ON FUNCTION pg_current_logfile(text) FROM public; REVOKE EXECUTE ON FUNCTION pg_promote(boolean, integer) FROM public; +REVOKE EXECUTE ON FUNCTION pg_demote(boolean, boolean, integer) FROM public; REVOKE EXECUTE ON FUNCTION pg_stat_reset() FROM public; REVOKE EXECUTE ON FUNCTION pg_stat_reset_shared(text) FROM public; diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat index 082a11f270..9e4d000d00 100644 --- a/src/include/catalog/pg_proc.dat +++ b/src/include/catalog/pg_proc.dat @@ -6084,6 +6084,10 @@ proname => 'pg_promote', provolatile => 'v', prorettype => 'bool', proargtypes => 'bool int4', proargnames => '{wait,wait_seconds}', prosrc => 'pg_promote' }, +{ oid => '8967', descr => 'demote production server', + proname => 'pg_demote', provolatile => 'v', prorettype => 'bool', + proargtypes => 'bool bool int4', proargnames => '{fast,wait,wait_seconds}', + prosrc => 'pg_demote' }, { oid => '2848', descr => 'switch to new wal file', proname => 'pg_switch_wal', provolatile => 'v', prorettype => 'pg_lsn', proargtypes => '', prosrc => 'pg_switch_wal' }, -- 2.20.1 --MP_/Mp45B_GpB5m14pibp/TRwlo Content-Type: text/x-patch Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename=v4-0004-demote-add-various-tests-related-to-demote-and-promo.patch ^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: typos @ 2022-04-13 17:40 Justin Pryzby <[email protected]> 0 siblings, 1 reply; 5+ messages in thread From: Justin Pryzby @ 2022-04-13 17:40 UTC (permalink / raw) To: Alvaro Herrera <[email protected]>; +Cc: David Rowley <[email protected]>; pgsql-hackers; Fabien COELHO <[email protected]> On Wed, Apr 13, 2022 at 07:29:34PM +0200, Alvaro Herrera wrote: > On 2022-Apr-11, David Rowley wrote: > > > and also skipped: > > 0016 (unsure if we should change these of pgindent is not touching it) > > 0017 (unsure if we should change these of pgindent is not touching it) > > I verified that pgindent will indeed not touch these changes by running > before and after. (I accepted one comment placement from that run that > touched a neighboring line.) > > I think pgindent is right not to modify vertical space very much, since > in many cases it amounts to a subjective decision. The patch seemed a > (small) improvement, and it seems hard to make too much of a fuss about > such things. Pushed them as a single commit. > > I hadn't noticed that Justin had posted a refreshed patch series, so I > don't know if the new ones match what I pushed. There were no changes - I had resent the patches that removed blank lines so it was apparent that they were "outstanding" / under discussion. There's (only) a few remaining. Attachments: [text/x-diff] 0001-comment-spaces.patch (1.9K, ../../[email protected]/2-0001-comment-spaces.patch) download | inline diff: From 543b9d77763da814cf1a99938252eb16a0a7d131 Mon Sep 17 00:00:00 2001 From: Justin Pryzby <[email protected]> Date: Sat, 12 Mar 2022 14:55:18 -0600 Subject: [PATCH 1/4] comment spaces --- src/backend/storage/file/fd.c | 2 +- src/include/replication/message.h | 2 +- src/include/tsearch/ts_type.h | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/backend/storage/file/fd.c b/src/backend/storage/file/fd.c index 14b77f28617..24704b6a023 100644 --- a/src/backend/storage/file/fd.c +++ b/src/backend/storage/file/fd.c @@ -912,7 +912,7 @@ InitFileAccess(void) void InitTemporaryFileAccess(void) { - Assert(SizeVfdCache != 0); /* InitFileAccess() needs to have run*/ + Assert(SizeVfdCache != 0); /* InitFileAccess() needs to have run */ Assert(!temporary_files_allowed); /* call me only once */ /* diff --git a/src/include/replication/message.h b/src/include/replication/message.h index 7d7785292f1..b9686c28550 100644 --- a/src/include/replication/message.h +++ b/src/include/replication/message.h @@ -32,7 +32,7 @@ typedef struct xl_logical_message extern XLogRecPtr LogLogicalMessage(const char *prefix, const char *message, size_t size, bool transactional); -/* RMGR API*/ +/* RMGR API */ #define XLOG_LOGICAL_MESSAGE 0x00 void logicalmsg_redo(XLogReaderState *record); void logicalmsg_desc(StringInfo buf, XLogReaderState *record); diff --git a/src/include/tsearch/ts_type.h b/src/include/tsearch/ts_type.h index a2008f5504b..689b2d1cfb6 100644 --- a/src/include/tsearch/ts_type.h +++ b/src/include/tsearch/ts_type.h @@ -171,7 +171,7 @@ typedef struct extern PGDLLIMPORT const int tsearch_op_priority[OP_COUNT]; -/* get operation priority by its code*/ +/* get operation priority by its code */ #define OP_PRIORITY(x) ( tsearch_op_priority[(x) - 1] ) /* get QueryOperator priority */ #define QO_PRIORITY(x) OP_PRIORITY(((QueryOperator *) (x))->oper) -- 2.17.1 [text/x-diff] 0002-doc-review-locales.patch (3.8K, ../../[email protected]/3-0002-doc-review-locales.patch) download | inline diff: From e84373bd78d6634781536a96a083cf26c87aa53e Mon Sep 17 00:00:00 2001 From: Justin Pryzby <[email protected]> Date: Fri, 25 Mar 2022 13:04:48 -0500 Subject: [PATCH 3/4] doc review: locales f2553d43060edb210b36c63187d52a632448e1d2 --- doc/src/sgml/charset.sgml | 12 ++++++------ doc/src/sgml/ref/initdb.sgml | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/doc/src/sgml/charset.sgml b/doc/src/sgml/charset.sgml index d60d3207fd4..b95303fb893 100644 --- a/doc/src/sgml/charset.sgml +++ b/doc/src/sgml/charset.sgml @@ -314,7 +314,7 @@ initdb --locale=sv_SE A locale can be selected separately for each database. The SQL command <command>CREATE DATABASE</command> and its command-line equivalent <command>createdb</command> have options for that. Use this for example - if a database cluster houses databases for multiple tennants with + if a database cluster houses databases for multiple tenants with different requirements. </para> </listitem> @@ -346,7 +346,7 @@ initdb --locale=sv_SE providers</firstterm>. This specifies which library supplies the locale data. One standard provider name is <literal>libc</literal>, which uses the locales provided by the operating system C library. These are the - locales that most tools provided by the operating system use. Another + locales used by most tools provided by the operating system. Another provider is <literal>icu</literal>, which uses the external ICU<indexterm><primary>ICU</primary></indexterm> library. ICU locales can only be used if support for ICU was configured when PostgreSQL was built. @@ -361,8 +361,8 @@ initdb --locale=sv_SE <programlisting> initdb --locale-provider=icu --icu-locale=en </programlisting> - See the description of the respective commands and programs for the - respective details. Note that you can mix locale providers on different + See the description of the respective commands and programs for + details. Note that you can mix locale providers at different granularities, for example use <literal>libc</literal> by default for the cluster but have one database that uses the <literal>icu</literal> provider, and then have collation objects using either provider within @@ -610,8 +610,8 @@ SELECT * FROM test1 ORDER BY a || b COLLATE "fr_FR"; definition has a <firstterm>provider</firstterm> that specifies which library supplies the locale data. One standard provider name is <literal>libc</literal>, which uses the locales provided by the - operating system C library. These are the locales that most tools - provided by the operating system use. Another provider + operating system C library. These are the locales used by most tools + provided by the operating system. Another provider is <literal>icu</literal>, which uses the external ICU<indexterm><primary>ICU</primary></indexterm> library. ICU locales can only be used if support for ICU was configured when PostgreSQL was built. diff --git a/doc/src/sgml/ref/initdb.sgml b/doc/src/sgml/ref/initdb.sgml index f5d633b0afa..c9ffaaecfb9 100644 --- a/doc/src/sgml/ref/initdb.sgml +++ b/doc/src/sgml/ref/initdb.sgml @@ -108,7 +108,7 @@ PostgreSQL documentation Alternatively, the ICU library can be used to provide locale services. (Again, this only sets the default for subsequently created databases.) To select this option, specify <literal>--locale-provider=icu</literal>. - To chose the specific ICU locale ID to apply, use the option + To choose the specific ICU locale ID to apply, use the option <option>--icu-locale</option>. Note that for implementation reasons and to support legacy code, <command>initdb</command> will still select and initialize libc locale -- 2.17.1 [text/x-diff] 0003-doc-review-row-filters-for-logical-replication.patch (1.1K, ../../[email protected]/4-0003-doc-review-row-filters-for-logical-replication.patch) download | inline diff: From 7ebb9ee1761df8a9379e128e2d899a75d28ad2a7 Mon Sep 17 00:00:00 2001 From: Justin Pryzby <[email protected]> Date: Fri, 25 Mar 2022 12:22:58 -0500 Subject: [PATCH 4/4] doc review: row filters for logical replication 52e4f0cd472d39d07732b99559989ea3b615be78 --- doc/src/sgml/ref/create_publication.sgml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/src/sgml/ref/create_publication.sgml b/doc/src/sgml/ref/create_publication.sgml index fb2d013393b..f4b44d99a88 100644 --- a/doc/src/sgml/ref/create_publication.sgml +++ b/doc/src/sgml/ref/create_publication.sgml @@ -252,8 +252,8 @@ CREATE PUBLICATION <replaceable class="parameter">name</replaceable> system columns. If your publication contains a partitioned table, the publication parameter <literal>publish_via_partition_root</literal> determines if it uses the - partition's row filter (if the parameter is false, the default) or the root - partitioned table's row filter. + partition's row filter (when the parameter is false, which is the default) + or the root partitioned table's row filter. </para> <para> -- 2.17.1 ^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: typos @ 2022-04-13 21:39 David Rowley <[email protected]> parent: Justin Pryzby <[email protected]> 0 siblings, 1 reply; 5+ messages in thread From: David Rowley @ 2022-04-13 21:39 UTC (permalink / raw) To: Justin Pryzby <[email protected]>; +Cc: Alvaro Herrera <[email protected]>; pgsql-hackers; Fabien COELHO <[email protected]> (For the future, just to make discussions easier, it would be good if you could have git format-patch -v N to give a unique version number to these patches) On Thu, 14 Apr 2022 at 05:40, Justin Pryzby <[email protected]> wrote: > There's (only) a few remaining. I've pushed 0001 and 0002 of the 3rd batch of patches. I left 0003 as I just didn't feel it was a meaningful enough improvement. From docs/, if I do: $ git grep ", which is the default" | wc -l 9 $ git grep ", the default" | wc -l 64 You're proposing to make the score 10, 63. I'm not sure if that's a good direction to go in. David ^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: typos @ 2022-04-14 00:33 Justin Pryzby <[email protected]> parent: David Rowley <[email protected]> 0 siblings, 1 reply; 5+ messages in thread From: Justin Pryzby @ 2022-04-14 00:33 UTC (permalink / raw) To: David Rowley <[email protected]>; +Cc: Alvaro Herrera <[email protected]>; pgsql-hackers; Fabien COELHO <[email protected]> On Thu, Apr 14, 2022 at 09:39:42AM +1200, David Rowley wrote: > On Thu, 14 Apr 2022 at 05:40, Justin Pryzby <[email protected]> wrote: > > There's (only) a few remaining. > > I've pushed 0001 and 0002 of the 3rd batch of patches. I left 0003 as Thanks > I just didn't feel it was a meaningful enough improvement. > > From docs/, if I do: > > $ git grep ", which is the default" | wc -l > 9 > > $ git grep ", the default" | wc -l > 64 > > You're proposing to make the score 10, 63. I'm not sure if that's a > good direction to go in. Well, I'm proposing to change the only instance of this: $ git grep -F ", the default)" doc/src/sgml/ref/create_publication.sgml: partition's row filter (if the parameter is false, the default) or the root Maybe what's needed is more like this. If the publication contains a partitioned table, and the publication parameter <literal>publish_via_partition_root</literal> is false (the default), then the row filter is taken from the partition; otherwise, the row filter is taken from the root partitioned table. I'll plan to keep this around and may come back to it later. On Thu, Apr 14, 2022 at 08:56:22AM +1200, David Rowley wrote: > I've left out the following change as it does not seem to be bringing > any sort of consistency to the docs overall. It only brings > consistency to a single source file in the docs. > > - You need <productname>zstd</productname>, if you want to support > + You need <productname>ZSTD</productname>, if you want to support > > See: git grep -i ">zstd<" It may not be worth changing just this one line, but the reason I included it here is for consistency: $ git grep 'zstd.*product' doc doc/src/sgml/config.sgml: <literal>zstd</literal> (if <productname>PostgreSQL</productname> $ git grep 'ZSTD.*product' doc doc/src/sgml/install-windows.sgml: <term><productname>ZSTD</productname></term> doc/src/sgml/install-windows.sgml: Required for supporting <productname>ZSTD</productname> compression doc/src/sgml/installation.sgml: You need <productname>ZSTD</productname>, if you want to support doc/src/sgml/installation.sgml: Build with <productname>ZSTD</productname> compression support. If we were to change it, maybe they should all say "Zstandard (zstd)". ZSTD looks like an acronym, which I think it is not, and Zstandard indicates how to pronounce it. ^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: typos @ 2022-04-19 11:05 Alvaro Herrera <[email protected]> parent: Justin Pryzby <[email protected]> 0 siblings, 0 replies; 5+ messages in thread From: Alvaro Herrera @ 2022-04-19 11:05 UTC (permalink / raw) To: Justin Pryzby <[email protected]>; +Cc: David Rowley <[email protected]>; pgsql-hackers; Fabien COELHO <[email protected]>; Amit Kapila <[email protected]> CCing Amit K, because I propose a few relatively minor changes to logical rep docs. On 2022-Apr-13, Justin Pryzby wrote: > $ git grep -F ", the default)" > doc/src/sgml/ref/create_publication.sgml: partition's row filter (if the parameter is false, the default) or the root > > Maybe what's needed is more like this. > > If the publication contains a partitioned table, and the publication parameter > <literal>publish_via_partition_root</literal> is false (the default), then the > row filter is taken from the partition; otherwise, the row filter is taken > from the root partitioned table. Yeah, more invasive rewording seems called for. I propose this: For publications containing partitioned tables, the row filter for each partition is taken from the published partitioned table if the publication parameter <literal>publish_via_partition_root</literal> is true, or from the partition itself if it is false (the default). I think we should also mention that this parameter affects row filters, in the <varlistentry> for the WITH clause. Currently it has <term><literal>publish_via_partition_root</literal> (<type>boolean</type>)</term> <listitem> <para> This parameter determines whether changes in a partitioned table (or on its partitions) contained in the publication will be published using the identity and schema of the partitioned table rather than that of the individual partitions that are actually changed; the latter is the default. Enabling this allows the changes to be replicated into a non-partitioned table or a partitioned table consisting of a different set of partitions. </para> I propose to add <term><literal>publish_via_partition_root</literal> (<type>boolean</type>)</term> <listitem> <para> This parameter determines whether changes in a partitioned table (or on its partitions) contained in the publication will be published using the identity and schema of the partitioned table rather than that of the individual partitions that are actually changed; the latter is the default. Enabling this allows the changes to be replicated into a non-partitioned table or a partitioned table consisting of a different set of partitions. </para> <para> This parameter also affects how row filters are chosen for partitions; see below for details. </para> More generally, I think we need to connect the WHERE keyword with "row filters" more explicitly. Right now, the parameter reference says If the optional <literal>WHERE</literal> clause is specified, rows for which the <replaceable class="parameter">expression</replaceable> evaluates to false or null will not be published. Note that parentheses are required around the expression. It has no effect on <literal>TRUNCATE</literal> commands. I propose to make it "If the optional WHERE clause is specified, it defines a <firstterm>row filter</firstterm> expression. Rows for which the row filter expression evaluates to false ..." > $ git grep 'zstd.*product' doc > doc/src/sgml/config.sgml: <literal>zstd</literal> (if <productname>PostgreSQL</productname> > $ git grep 'ZSTD.*product' doc > doc/src/sgml/install-windows.sgml: <term><productname>ZSTD</productname></term> > doc/src/sgml/install-windows.sgml: Required for supporting <productname>ZSTD</productname> compression > doc/src/sgml/installation.sgml: You need <productname>ZSTD</productname>, if you want to support > doc/src/sgml/installation.sgml: Build with <productname>ZSTD</productname> compression support. I don't see any official sources calling it all-uppercase ZSTD. In a quick non-scientific survey, most seem to use Zstd or zstd. The non-abbreviated official name is Zstandard, but it's hard to find any places using that spelling, and I don't think our docs are a place to educate people on what the official name or pronunciation is. I propose we standardize on <productname>Zstd</productname> everywhere. Users can look it up if they're really interested. -- Álvaro Herrera PostgreSQL Developer — https://www.EnterpriseDB.com/ ^ permalink raw reply [nested|flat] 5+ messages in thread
end of thread, other threads:[~2022-04-19 11:05 UTC | newest] Thread overview: 5+ messages (download: mbox mbox.gz follow: Atom feed) -- links below jump to the message on this page -- 2020-07-31 16:07 [PATCH 3/4] demote: add pg_demote() function Jehan-Guillaume de Rorthais <[email protected]> 2022-04-13 17:40 Re: typos Justin Pryzby <[email protected]> 2022-04-13 21:39 ` Re: typos David Rowley <[email protected]> 2022-04-14 00:33 ` Re: typos Justin Pryzby <[email protected]> 2022-04-19 11:05 ` Re: typos Alvaro Herrera <[email protected]>
This inbox is served by agora; see mirroring instructions for how to clone and mirror all data and code used for this inbox