Re: broken tables on hot standby after migration on PostgreSQL 16 (3x times last month)

2024-05-20 Thread Pavel Stehule
Hi



>
> Another question: Do you use pg_repack or such?
>

pg_repack was used for some tables, but I found broken tables, where
pg_repack was not used.

Regards

Pavel

>
> Greetings,
>
> Andres Freund
>


Re: Speed up clean meson builds by ~25%

2024-05-20 Thread Peter Eisentraut

On 19.05.24 00:09, Andres Freund wrote:

On 2024-05-18 00:35:08 +0200, Peter Eisentraut wrote:

I retested the patch from 2024-04-07 (I think that's the one that "fixed
that"?  There are multiple "v1" patches in this thread.) using gcc-14 and
clang-18, with ccache disabled of course.  The measured effects of the patch
are:

gcc-14:   1% slower
clang-18: 3% faster

So with that, it doesn't seem very interesting.

I wonder whether the reason you're seing less benefit than Jelte is that - I'm
guessing - you now used ninja 1.12 and Jelte something older.  Ninja 1.12
prioritizes building edges using a "critical path" heuristic, leading to
scheduling nodes with more incoming dependencies, and deeper in the dependency
graph earlier.


Yes!  Very interesting!

With ninja 1.11 and gcc-14, I see the patch gives about a 17% speedup.




Re: Cleaning up perl code

2024-05-20 Thread Michael Paquier
On Tue, May 21, 2024 at 06:00:00AM +0300, Alexander Lakhin wrote:
> I reviewed my collection of unica I gathered for several months, but had
> found some of them too minor/requiring more analysis.
> Then I added more with perlcritic's policy UnusedVariables, and also
> checked for unused subs with a script from blogs.perl.org (and it confirmed
> my only previous find of that kind).

Nice catches from both of you.  The two ones in
generate-wait_event_types.pl are caused by me, actually.

Not sure about the changes in the errcodes scripts, though.  The
current state of thing can be also useful when it comes to debugging
the parsing, and it does not hurt to keep the parsing rules the same
across the board.

>> The scripts parsing errcodes.txt really should be refactored into using
>> a common module, but that's a patch for another day.
> 
> Agree, and I would leave 005_negotiate_encryption.pl (with $node_conf,
> $server_config unused since d39a49c1e) aside for another day too.

I'm not sure about these ones as each one of these scripts have their
own local tweaks.  Now, if there is a cleaner picture with a .pm
module I don't see while reading the whole, why not as long as it
improves the code.
--
Michael


signature.asc
Description: PGP signature


Re: inconsistent quoting in error messages

2024-05-20 Thread Peter Smith
On Tue, May 21, 2024 at 2:56 PM Kyotaro Horiguchi
 wrote:
>
> I noticed that there are slightly inconsistent messages regarding
> quoting policies.
>
> > This happens if you temporarily set "wal_level=minimal" on the server.
> > WAL generated with "full_page_writes=off" was replayed during online backup
>
> > pg_log_standby_snapshot() can only be used if "wal_level" >= "replica"
>
> > WAL streaming ("max_wal_senders" > 0) requires "wal_level" to be "replica" 
> > or "logical"
>
> I think it's best to quote variable names and values separately, like
> "wal_level" = "minimal" (but not use quotes for numeric values), as it
> seems to be the most common practice. Anyway, we might want to unify
> them.
>
>
> Likewise, I saw two different versions of values with units.
>
> > "max_stack_depth" must not exceed %ldkB.
> > "vacuum_buffer_usage_limit" must be 0 or between %d kB and %d kB
>
> I'm not sure, but it seems like the latter version is more common.
>
> regards.
>

Hi,

I think it might be better to keep all the discussions about GUC
quoting and related topics like this confined to the main thread here
[1]. Otherwise, we might end up with a bunch of competing patches.

==
[1] 
https://www.postgresql.org/message-id/CAHut%2BPv-kSN8SkxSdoHano_wPubqcg5789ejhCDZAcLFceBR-w%40mail.gmail.com

Kind Regards,
Peter Smith.
Fujitsu Australia




inconsistent quoting in error messages

2024-05-20 Thread Kyotaro Horiguchi
I noticed that there are slightly inconsistent messages regarding
quoting policies.

> This happens if you temporarily set "wal_level=minimal" on the server.
> WAL generated with "full_page_writes=off" was replayed during online backup
 
> pg_log_standby_snapshot() can only be used if "wal_level" >= "replica"

> WAL streaming ("max_wal_senders" > 0) requires "wal_level" to be "replica" or 
> "logical"

I think it's best to quote variable names and values separately, like
"wal_level" = "minimal" (but not use quotes for numeric values), as it
seems to be the most common practice. Anyway, we might want to unify
them.


Likewise, I saw two different versions of values with units.

> "max_stack_depth" must not exceed %ldkB.
> "vacuum_buffer_usage_limit" must be 0 or between %d kB and %d kB

I'm not sure, but it seems like the latter version is more common.

regards.

-- 
Kyotaro Horiguchi
NTT Open Source Software Center




Re: Postgres and --config-file option

2024-05-20 Thread Michael Paquier
On Mon, May 20, 2024 at 12:20:02PM +0300, Aleksander Alekseev wrote:
> Robert Haas  writes:
>> I agree that it's not necessary or particularly useful for this hint
>> to be exhaustive.  I could get behind your suggestion of
>> s/You must specify/Specify/, but I also think it's fine to do nothing.
> 
> Fair enough, let's leave the help message as is then. I closed the
> corresponding CF entry.

I'm OK to leave this be, as well.
--
Michael


signature.asc
Description: PGP signature


Re: doc regexp_replace replacement string \n does not explained properly

2024-05-20 Thread David G. Johnston
On Monday, May 20, 2024, jian he  wrote:

> hi.
>
> https://www.postgresql.org/docs/current/functions-
> matching.html#FUNCTIONS-POSIX-REGEXP
>
>
>  If there is a match,
> the source string is returned with the replacement string substituted
> for the matching substring.


>
This happens regardless of the presence of parentheses.


>
>  The replacement string can contain \n,
> where n is 1 through 9, to indicate that the source substring matching
> the n'th parenthesized subexpression of the pattern should be
> inserted, and it can contain \& to indicate that the substring
> matching the entire pattern should be inserted.


 Then if the replacement text contains “\n” expressions those are replaced
with text captured from the corresponding parentheses group.


> <<
> i think it explained example like:
> SELECT regexp_replace('foobarbaz', 'b(..)', 'X\1Y', 'g');


global - find two matches to process.

foobarbaz
fooX\1YX\1Y
fooXarYXazY


>
> but it does not seem to explain cases like:
> SELECT regexp_replace('foobarbaz', 'b(..)', 'X\2Y', 'g');
>
>
foobarbaz
fooX\2YX\2Y
fooX{empty string, no second capture group}YX{empty}Y
fooXYXY

The docs are correct, though I suppose being explicit that a missing
capture group results in an empty string substitution instead of an error
is probably warranted.

David J.


doc regexp_replace replacement string \n does not explained properly

2024-05-20 Thread jian he
hi.

https://www.postgresql.org/docs/current/functions-matching.html#FUNCTIONS-POSIX-REGEXP
<<

Re: Cleaning up perl code

2024-05-20 Thread Alexander Lakhin

Hello Dagfinn,

Thank you for paying attention to it and improving the possible fix!

20.05.2024 23:39, Dagfinn Ilmari Mannsåker wrote:

Nice cleanup!  Did you use some static analysis tool, or did look for
them manually?


I reviewed my collection of unica I gathered for several months, but had
found some of them too minor/requiring more analysis.
Then I added more with perlcritic's policy UnusedVariables, and also
checked for unused subs with a script from blogs.perl.org (and it confirmed
my only previous find of that kind).


  If I add [Variables::ProhibitUnusedVariables] to
src/tools/perlcheck/perlcriticrc, it finds a few more, see the attached
patch.


Yes, I saw unused $sqlstates, but decided that they are meaningful enough
to stay. Though maybe enabling ProhibitUnusedVariables justifies fixing
them too.


The scripts parsing errcodes.txt really should be refactored into using
a common module, but that's a patch for another day.


Agree, and I would leave 005_negotiate_encryption.pl (with $node_conf,
$server_config unused since d39a49c1e) aside for another day too.

Best regards,
Alexander




Path to unreverting "Allow planner to use Merge Append to efficiently implement UNION"

2024-05-20 Thread David Rowley
Earlier today in [1], a bug was reported regarding a problem with the
code added in 66c0185a3 where I'd failed to handle the case correctly
where the UNION's targetlist has columns which are not sortable.  For
pg_class, that's relfrozenxid, relminmxid and relacl.

The most minimal reproducer prior to the revert is:

set enable_hashagg=0;
explain (costs off) select '123'::xid union select '123'::xid;

There is still some ongoing discussion about this on the release
mailing list as per mentioned by Tom in the commit message in
7204f3591.

At some point that discussion is going to need to circle back onto
-hackers again, and since I've already written a patch to fix the
issue and un-revert Tom's revert. I just wanted a place on -hackers to
allow that code to be viewed and discussed.  I did also post a patch
on [2], but that no longer applies to master due to the revert.

I'll allow the RMT to choose where the outcome of the RMT decision
goes.  Let this thread be for at least the coding portion of this or
be my thread for this patch for the v18 cycle if the RMT rules in
favour of keeping that code reverted for v17.

I've attached 2 patches.

0001 is a simple revert of Tom's revert (7204f3591).
0002 fixes the issue reported by Hubert.

If anyone wants to have a look, I'd be grateful for that.  Tom did
call for further review after this being the 4th issue reported for
66c0185a3.

David

[1] https://postgr.es/message-id/Zktzf926vslR35Fv%40depesz.com
[2] 
https://www.postgresql.org/message-id/CAApHDvpDQh1NcL7nAsd3YAKj4vgORwesB3GYuNPnEXXRfA2g4w%40mail.gmail.com


v2-0001-Revert-Revert-commit-66c0185a3-and-follow-on-patc.patch
Description: Binary data


v2-0002-Fix-UNION-planner-bug-and-add-regression-test.patch
Description: Binary data


Re: recovery modules

2024-05-20 Thread Nathan Bossart
rebased

-- 
Nathan Bossart
Amazon Web Services: https://aws.amazon.com
>From c23ddbe1dac8b9a79db31ad67df423848e475905 Mon Sep 17 00:00:00 2001
From: Nathan Bossart 
Date: Wed, 15 Feb 2023 14:28:53 -0800
Subject: [PATCH v23 1/5] introduce routine for checking mutually exclusive
 string GUCs

---
 src/backend/postmaster/pgarch.c |  8 +++-
 src/backend/utils/misc/guc.c| 22 ++
 src/include/utils/guc.h |  3 +++
 3 files changed, 28 insertions(+), 5 deletions(-)

diff --git a/src/backend/postmaster/pgarch.c b/src/backend/postmaster/pgarch.c
index 02f91431f5..5f1a6f190d 100644
--- a/src/backend/postmaster/pgarch.c
+++ b/src/backend/postmaster/pgarch.c
@@ -912,11 +912,9 @@ LoadArchiveLibrary(void)
 {
ArchiveModuleInit archive_init;
 
-   if (XLogArchiveLibrary[0] != '\0' && XLogArchiveCommand[0] != '\0')
-   ereport(ERROR,
-   (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
-errmsg("both \"archive_command\" and 
\"archive_library\" set"),
-errdetail("Only one of \"archive_command\", 
\"archive_library\" may be set.")));
+   (void) CheckMutuallyExclusiveStringGUCs(XLogArchiveLibrary, 
"archive_library",
+   
XLogArchiveCommand, "archive_command",
+   
ERROR);
 
/*
 * If shell archiving is enabled, use our special initialization 
function.
diff --git a/src/backend/utils/misc/guc.c b/src/backend/utils/misc/guc.c
index 547cecde24..05dc5303bc 100644
--- a/src/backend/utils/misc/guc.c
+++ b/src/backend/utils/misc/guc.c
@@ -2659,6 +2659,28 @@ ReportGUCOption(struct config_generic *record)
pfree(val);
 }
 
+/*
+ * If both parameters are set, emits a log message at 'elevel' and returns
+ * false.  Otherwise, returns true.
+ */
+bool
+CheckMutuallyExclusiveStringGUCs(const char *p1val, const char *p1name,
+const char 
*p2val, const char *p2name,
+int elevel)
+{
+   if (p1val[0] != '\0' && p2val[0] != '\0')
+   {
+   ereport(elevel,
+   (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
+errmsg("both \"%s\" and \"%s\" set", p1name, 
p2name),
+errdetail("Only one of \"%s\", \"%s\" may be 
set.",
+  p1name, p2name)));
+   return false;
+   }
+
+   return true;
+}
+
 /*
  * Convert a value from one of the human-friendly units ("kB", "min" etc.)
  * to the given base unit.  'value' and 'unit' are the input value and unit
diff --git a/src/include/utils/guc.h b/src/include/utils/guc.h
index e4a594b5e8..018bb7e55b 100644
--- a/src/include/utils/guc.h
+++ b/src/include/utils/guc.h
@@ -376,6 +376,9 @@ extern void RestrictSearchPath(void);
 extern void AtEOXact_GUC(bool isCommit, int nestLevel);
 extern void BeginReportingGUCOptions(void);
 extern void ReportChangedGUCOptions(void);
+extern bool CheckMutuallyExclusiveStringGUCs(const char *p1val, const char 
*p1name,
+   
 const char *p2val, const char *p2name,
+   
 int elevel);
 extern void ParseLongOption(const char *string, char **name, char **value);
 extern const char *get_config_unit_name(int flags);
 extern bool parse_int(const char *value, int *result, int flags,
-- 
2.39.3 (Apple Git-146)

>From b35cd2dd0b360a50af7ab9175b2887646ba57f37 Mon Sep 17 00:00:00 2001
From: Nathan Bossart 
Date: Wed, 15 Feb 2023 10:36:00 -0800
Subject: [PATCH v23 2/5] refactor code for restoring via shell

---
 src/backend/Makefile  |   2 +-
 src/backend/access/transam/timeline.c |  12 +-
 src/backend/access/transam/xlog.c |  50 -
 src/backend/access/transam/xlogarchive.c  | 167 ---
 src/backend/access/transam/xlogrecovery.c |   3 +-
 src/backend/meson.build   |   1 +
 src/backend/postmaster/startup.c  |  16 +-
 src/backend/restore/Makefile  |  18 ++
 src/backend/restore/meson.build   |   5 +
 src/backend/restore/shell_restore.c   | 245 ++
 src/include/Makefile  |   2 +-
 src/include/access/xlogarchive.h  |   9 +-
 src/include/meson.build   |   1 +
 src/include/postmaster/startup.h  |   1 +
 src/include/restore/shell_restore.h   |  26 +++
 src/tools/pgindent/typedefs.list  |   1 +
 16 files changed, 407 insertions(+), 152 deletions(-)
 create mode 100644 src/backend/restore/Makefile
 create mode 100644 

Re: First draft of PG 17 release notes

2024-05-20 Thread Amit Langote
On Thu, May 9, 2024 at 1:04 PM Bruce Momjian  wrote:
> I have committed the first draft of the PG 17 release notes;  you can
> see the results here:
>
> https://momjian.us/pgsql_docs/release-17.html
>
> It will be improved until the final release.  The item count is 188,
> which is similar to recent releases:
>
> release-10:  189
> release-11:  170
> release-12:  180
> release-13:  178
> release-14:  220
> release-15:  184
> release-16:  206
> release-17:  188
>
> I welcome feedback.  For some reason it was an easier job than usual.

Thanks Bruce for working on this as always.

Failed to notice when I read the notes before:



Add SQL/JSON constructor functions JSON(), JSON_SCALAR(), and
JSON_SERIALIZE() (Amit Langote)



Should be:



Add SQL/JSON constructor functions JSON(), JSON_SCALAR(), and
JSON_SERIALIZE() (Nikita Glukhov, Teodor Sigaev, Oleg Bartunov,
Alexander Korotkov, Andrew Dunstan, Amit Langote)



Patch attached.

-- 
Thanks, Amit Langote


sql-json-credits.patch
Description: Binary data


Re: Injection points: preloading and runtime arguments

2024-05-20 Thread Michael Paquier
On Mon, May 20, 2024 at 05:01:15PM +0500, Andrey M. Borodin wrote:
> Both features look useful to me.
> I've tried to rebase my test of CV sleep during multixact generation[0]. I 
> used it like this:
> 
> INJECTION_POINT_PRELOAD("GetNewMultiXactId-done");
> multi = GetNewMultiXactId(nmembers, ); // starts critsection
> INJECTION_POINT("GetNewMultiXactId-done");

Thanks for the feedback.

> And it fails like this:
> 
> 2024-05-20 16:50:40.430 +05 [21830] 001_multixact.pl LOG:  statement: select 
> test_create_multixact();
> TRAP: failed Assert("CritSectionCount == 0 || 
> (context)->allowInCritSection"), File: "mcxt.c", Line: 1185, PID: 21830
> 0   postgres0x000101452ed0 
> ExceptionalCondition + 220
> 1   postgres0x0001014a6050 MemoryContextAlloc 
> + 208
> 2   postgres0x0001011c3bf0 
> dsm_create_descriptor + 72
> 3   postgres0x0001011c3ef4 dsm_attach + 400
> 4   postgres0x0001014990d8 dsa_attach + 24
> 5   postgres0x0001011c716c init_dsm_registry 
> + 240
> 6   postgres0x0001011c6e60 GetNamedDSMSegment 
> + 456
> 7   injection_points.dylib  0x000101c871f8 
> injection_init_shmem + 60
> 8   injection_points.dylib  0x000101c86f1c injection_wait + 64
> 9   postgres0x00010148e228 
> InjectionPointRunInternal + 376
> 10  postgres0x00010148e0a4 InjectionPointRun 
> + 32
> 11  postgres0x000100cab798 
> MultiXactIdCreateFromMembers + 344
> 12  postgres0x000100cab604 MultiXactIdCreate 
> + 312
> 
> Am I doing something wrong? Seems like extension have to know too that it is 
> preloaded.

Your stack is pointing at the shared memory section initialized in the
module injection_points, which is a bit of a chicken-and-egg problem
because you'd want an extra preload to happen before even that, like a
pre-preload.  From what I can see, you have a good point about the
shmem initialized in the module: injection_points_preload() should
call injection_init_shmem() so as this area would not trigger the
assertion.

However, there is a second thing here inherent to your test: shouldn't
the script call injection_points_preload() to make sure that the local
cache behind GetNewMultiXactId-done is fully allocated and prepared
for the moment where injection point will be run?

So I agree that 0002 ought to call injection_init_shmem() when calling
injection_points_preload(), but it also seems to me that the test is
missing the fact that it should heat the backend cache to avoid the
allocations in the critical sections.

Note that I disagree with taking a shortcut in the backend-side
injection point code where we would bypass CritSectionCount or
allowInCritSection.  These states should stay consistent for the sake
of the callbacks registered so as these can rely on the same stack and
conditions as the code where they are called.
--
Michael


signature.asc
Description: PGP signature


Re: pg_combinebackup does not detect missing files

2024-05-20 Thread David Steele

On 5/21/24 03:09, Robert Haas wrote:

On Fri, May 17, 2024 at 6:14 PM David Steele  wrote:

Then intentionally corrupt a file in the incr backup:

$ truncate -s 0 test/backup/incr1/base/5/3764_fsm

In this case pg_verifybackup will error:

$ pg_verifybackup test/backup/incr1
pg_verifybackup: error: "base/5/3764_fsm" has size 0 on disk but size
24576 in the manifest

But pg_combinebackup does not complain:

$ pg_combinebackup test/backup/full test/backup/incr1 -o test/backup/combine
$ ls -lah test/backup/combine/base/5/3764_fsm
-rw--- 1 dev dialout 0 May 17 22:08 test/backup/combine/base/5/3764_fsm

It would be nice if pg_combinebackup would (at least optionally but
prefferrably by default) complain in this case rather than the user
needing to separately run pg_verifybackup.


My first reaction here is that it would be better to have people run
pg_verifybackup for this. If we try to do this in pg_combinebackup,
we're either going to be quite limited in the amount of validation we
can do (which might lure users into a false sense of security) or
we're going to make things quite a bit more complicated and expensive.

Perhaps there's something here that is worth doing; I haven't thought
about this deeply and can't really do so at present. I do believe in
reasonable error detection, which I hope goes without saying, but I
also believe strongly in orthogonality: a tool should do one job and
do it as well as possible.


OK, that seems like a good place to leave this for now.

Regards,
-David




Re: Streaming read-ready sequential scan code

2024-05-20 Thread Thomas Munro
On Tue, May 21, 2024 at 9:11 AM Melanie Plageman
 wrote:
> So, if you are seeing the slow-down mostly go away by reducing
> blocknums array size, does the regression only appear when the scan
> data is fully in shared buffers? Or is this blocknums other use
> (dealing with short reads)?

That must be true (that blocknums array is normally only "filled" in
the "fast path", where all buffers are found in cache).

> Is your theory that one worker ends up reading 16 blocks that should
> have been distributed across multiple workers?

Yes, it just jiggles the odds around a bit, introducing a bit of extra
unfairness by calling the callback in a tighter loop to build a little
batch, revealing a pre-existing problem.

The mistake in PHJ (problem #2 above) is that, once a worker decides
it would like all workers to stop inserting so it can increase the
number of buckets, it sets a flag to ask them to do that, and waits
for them to see it, but if there is a worker filtering all tuples out,
it never checks the "growth" flag.  So it scans all the way to the end
while the other guy waits.  Normally it checks that flag when it is
time to allocate a new chunk of memory, which seemed to make sense to
me at the time: if we've hit the needs-more-buckets (or
needs-more-batches) logic, then surely workers are inserting tuples
and will soon allocate a new chunk!  But, of course, here is the edge
case where that isn't true: we had bad estimates so hash table too
small (problem #1), we got lots of tuples clustered over a few heap
pages and decided to expand the hash table, but right at that moment,
matching tuples ran out so somebody had to finish the whole scan
without ever checking the flag (problem #2), and that someone happened
to have all the rest of the pages because we made the lookahead a bit
less fair (problem #3).  Nice confluence of problems.  I expect #2 and
#3 to be easy to fix, and I didn't look at the estimation problem #1
at all (perhaps a stats puzzle designed by the TPC to trip us up?).




Re: commitfest.postgresql.org is no longer fit for purpose

2024-05-20 Thread Maciek Sakrejda
On Sun, May 19, 2024 at 10:50 PM Thomas Munro  wrote:
> Sometimes I question the sanity of the whole thing.  Considering
> cfbot's original "zero-effort CI" goal (or I guess "zero-extra-effort"
> would be better), I was curious about what other projects had the same
> idea, or whether we're really just starting at the "wrong end", and
> came up with:
>
> https://github.com/getpatchwork/patchwork
> http://vger.kernel.org/bpfconf2022_material/lsfmmbpf2022-bpf-ci.pdf
> <-- example user
> https://github.com/patchew-project/patchew
>
> Actually cfbot requires more effort than those, because it's driven
> first by Commitfest app registration.  Those projects are extremists
> IIUC: just write to a mailing list, no other bureaucracy at all (at
> least for most participants, presumably administrators can adjust the
> status in some database when things go wrong?).  We're actually
> halfway to Gitlab et al already, with a web account and interaction
> required to start the process of submitting a patch for consideration.
> What I'm less clear on is who else has come up with the "bitrot" test
> idea, either at the mailing list or web extremist ends of the scale.
> Those are also generic tools, and cfbot obviously knows lots of things
> about PostgreSQL, like the "highlights" and probably more things I'm
> forgetting.

For what it's worth, a few years before cfbot, I had privately
attempted a similar idea for Postgres [1]. The project here is
basically a very simple API and infrastructure for running builds and
make check. A previous version [2] subscribed to the mailing lists and
used Travis CI (and accidentally spammed some Postgres committers
[3]). The project petered out as my work responsibilities shifted (and
to be honest, after I felt sheepish about the spamming).

I think cfbot is way, way ahead of where my project got at this point.
But since you asked about other similar projects, I'm happy to discuss
further if it's helpful to bounce ideas off someone who's thought
about the same problem (though not for a while now, I admit).

Thanks,
Maciek

[1]: https://github.com/msakrejda/pg-quilter
[2]: 
https://github.com/msakrejda/pg-quilter/blob/2038d9493f9aa7d43d3eb0aec1d299b94624602e/lib/pg-quilter/git_harness.rb
[3]: 
https://www.postgresql.org/message-id/flat/CAM3SWZQboGoVYAJNoPMx%3DuDLE%2BZh5k2MQa4dWk91YPGDxuY-gQ%40mail.gmail.com#e24bf57b77cfb6c440c999c018c46e92




Re: tydedef extraction - back to the future

2024-05-20 Thread Tom Lane
Andrew Dunstan  writes:
> Attached is an attempt to thread this needle. The core is a new perl 
> module that imports the current buildfarm client logic. The intention is 
> that once we have this, the buildfarm client will switch to using the 
> module (if found) rather than its own built-in logic. There is precedent 
> for this sort of arrangement (AdjustUpgrade.pm). Accompanying the new 
> module is a standalone perl script that uses the new module, and 
> replaces the current shell script (thus making it more portable).

Haven't read the code in detail, but +1 for concept.  A couple of
minor quibbles:

* Why not call the wrapper script "find_typedefs"?  Without the "s"
it seems rather confusing --- "which typedef is this supposed to
find, exactly?"

* The header comment for sub typedefs seems to have adequate detail
about what the arguments are, but that all ought to be propagated
into the --help output for the wrapper script.  Right now you
couldn't figure out how to use the wrapper without reading the
underlying module.

regards, tom lane




tydedef extraction - back to the future

2024-05-20 Thread Andrew Dunstan
Many years ago we in effect moved maintenance of the typedefs list for 
pgindent into the buildfarm client. The reason was that there were a 
number of typedefs that were platform dependent, so we wanted to have 
coverage across a number of platforms to get a comprehensive list.


Lately, this has caused some dissatisfaction, with people wanting the 
logic for this moved back into core code, among other reasons so we're 
not reliant on one person - me - for changes. I share this 
dissatisfaction. Indeed, IIRC the use of the buildfarm was originally 
intended as something of a stopgap. Still, we do need to multi-platform 
support.


Attached is an attempt to thread this needle. The core is a new perl 
module that imports the current buildfarm client logic. The intention is 
that once we have this, the buildfarm client will switch to using the 
module (if found) rather than its own built-in logic. There is precedent 
for this sort of arrangement (AdjustUpgrade.pm). Accompanying the new 
module is a standalone perl script that uses the new module, and 
replaces the current shell script (thus making it more portable).


One thing this is intended to provide for is getting typedefs for 
non-core code such as third party extensions, which isn't entirely 
difficult 
() 
but it's not as easy as it should be either.


Comments welcome.


cheers


andrew

--
Andrew Dunstan
EDB: https://www.enterprisedb.com
diff --git a/src/tools/find_typedef b/src/tools/find_typedef
deleted file mode 100755
index 24e9b76651..00
--- a/src/tools/find_typedef
+++ /dev/null
@@ -1,53 +0,0 @@
-#!/bin/sh
-
-# src/tools/find_typedef
-
-# This script attempts to find all typedef's in the postgres binaries
-# by using 'objdump' or local equivalent to print typedef debugging symbols.
-# We need this because pgindent needs a list of typedef names.
-#
-# For this program to work, you must have compiled all code with
-# debugging symbols.
-#
-# We intentionally examine all files in the targeted directories so as to
-# find both .o files and executables.  Therefore, ignore error messages about
-# unsuitable files being fed to objdump.
-#
-# This is known to work on Linux and on some BSDen, including macOS.
-#
-# Caution: on the platforms we use, this only prints typedefs that are used
-# to declare at least one variable or struct field.  If you have say
-# "typedef struct foo { ... } foo;", and then the structure is only ever
-# referenced as "struct foo", "foo" will not be reported as a typedef,
-# causing pgindent to indent the typedef definition oddly.  This is not a
-# huge problem, since by definition there's just the one misindented line.
-#
-# We get typedefs by reading "STABS":
-#http://www.informatik.uni-frankfurt.de/doc/texi/stabs_toc.html
-
-
-if [ "$#" -eq 0 -o ! -d "$1" ]
-then	echo "Usage:  $0 postgres_binary_directory [...]" 1>&2
-	exit 1
-fi
-
-for DIR
-do	# if objdump -W is recognized, only one line of error should appear
-	if [ `objdump -W 2>&1 | wc -l` -eq 1 ]
-	then	# Linux
-		objdump -W "$DIR"/* |
-		egrep -A3 '\(DW_TAG_typedef\)' |
-		awk ' $2 == "DW_AT_name" {print $NF}'
-	elif [ `readelf -w 2>&1 | wc -l` -gt 1 ]
-	then	# FreeBSD, similar output to Linux
-		readelf -w "$DIR"/* |
-		egrep -A3 '\(DW_TAG_typedef\)' |
-		awk ' $1 == "DW_AT_name" {print $NF}'
-	fi
-done |
-grep -v ' ' | # some typedefs have spaces, remove them
-sort |
-uniq |
-# these are used both for typedefs and variable names
-# so do not include them
-egrep -v '^(date|interval|timestamp|ANY)$'
diff --git a/src/tools/find_typedefs/PostgreSQL/FindTypedefs.pm b/src/tools/find_typedefs/PostgreSQL/FindTypedefs.pm
new file mode 100644
index 00..4f8167c824
--- /dev/null
+++ b/src/tools/find_typedefs/PostgreSQL/FindTypedefs.pm
@@ -0,0 +1,238 @@
+
+#
+# PostgreSQL/FindTypedefs.pm
+#
+# Module providing a function to find typedefs
+#
+# Copyright (c) 2021-2024, PostgreSQL Global Development Group
+#
+
+
+package PostgreSQL::FindTypedefs;
+
+use strict;
+use warnings FATAL => 'all';
+
+use Exporter qw(import);
+our @EXPORT = qw(typedefs);
+
+use Config;
+use File::Find;
+use Scalar::Util qw(reftype);
+
+# Returns a reference to a sorted array of typedef names
+#
+# Arguments are given as a hash. recognized names are:
+#binloc - where to find binary files. Required.
+#srcdir - where to find source files. Required.
+#msvc - boolean for whether we are using MSVC. Optional, default false.
+#hostopt - --host= setting if we are cross-compiling. Optional, default "".
+#
+# If binloc is given as an arrayref instead of as a scalar, it is taken
+# as a list of binary files to be examined rather than as a path to be
+# explored using File::Find / glob().
+#
+# If binloc is a scalar, then on MacOs it's the path to 

Re: Streaming read-ready sequential scan code

2024-05-20 Thread Melanie Plageman
Thank you to all of you for looking into  this.

On Sat, May 18, 2024 at 12:47 AM Thomas Munro  wrote:
>
> On Sat, May 18, 2024 at 11:30 AM Thomas Munro  wrote:
> > Andres happened to have TPC-DS handy, and reproduced that regression
> > in q15.  We tried some stuff and figured out that it requires
> > parallel_leader_participation=on, ie that this looks like some kind of
> > parallel fairness and/or timing problem.  It seems to be a question of
> > which worker finishes up processing matching rows, and the leader gets
> > a ~10ms head start but may be a little more greedy with the new
> > streaming code.  He tried reordering the table contents and then saw
> > 17 beat 16.  So for q15, initial indications are that this isn't a
> > fundamental regression, it's just a test that is sensitive to some
> > arbitrary conditions.
> >
> > I'll try to figure out some more details about that, ie is it being
> > too greedy on small-ish tables,
>
> After more debugging, we learned a lot more things...
>
> 1.  That query produces spectacularly bad estimates, so we finish up
> having to increase the number of buckets in a parallel hash join many
> times.  That is quite interesting, but unrelated to new code.
> 2.  Parallel hash join is quite slow at negotiating an increase in the
> number of hash bucket, if all of the input tuples are being filtered
> out by quals, because of the choice of where workers check for
> PHJ_GROWTH_NEED_MORE_BUCKETS.  That could be improved quite easily I
> think.  I have put that on my todo list 'cause that's also my code,
> but it's not a new issue it's just one that is now highlighted...
> 3.  This bit of read_stream.c is exacerbating unfairness in the
> underlying scan, so that 1 and 2 come together and produce a nasty
> slowdown, which goes away if you change it like so:
>
> -   BlockNumber blocknums[16];
> +   BlockNumber blocknums[1];
>
> I will follow up after some more study.

So, if you are seeing the slow-down mostly go away by reducing
blocknums array size, does the regression only appear when the scan
data is fully in shared buffers? Or is this blocknums other use
(dealing with short reads)?

Is your theory that one worker ends up reading 16 blocks that should
have been distributed across multiple workers?

- Melanie




Re: commitfest.postgresql.org is no longer fit for purpose

2024-05-20 Thread Akshat Jaimini
Hi everyone!

I would like to share another perspective on this as a relatively new user
of the commitfest app. I really like the concept behind the commitfest app
but while using it, sometimes I feel that we can do a better job at having
some sort of a 'metainfo' for the patch.
Although in some cases the patch title is enough to understand what it is
doing but for new contributors and reviewers it would be really helpful if
we can have something more explanatory instead of just having topics like
'bug fix', 'features' etc. Some sort of a small summarised description for
a patch explaining its history and need in brief would be really helpful
for people to get started instead of trying to make sense of a very large
email thread. This is a small addition but it would definitely make it
easier for new reviewers and contributors.

Regards,
Akshat Jaimini

On Mon, 20 May, 2024, 21:26 Matthias van de Meent, <
boekewurm+postg...@gmail.com> wrote:

> On Fri, 17 May 2024 at 15:02, Peter Eisentraut 
> wrote:
> >
> > On 17.05.24 09:32, Heikki Linnakangas wrote:
> > > Dunno about having to click a link or sparkly gold borders, but +1 on
> > > having a free-form text box for notes like that. Things like "cfbot
> says
> > > this has bitrotted" or "Will review this after other patch this depends
> > > on". On the mailing list, notes like that are both noisy and easily
> lost
> > > in the threads. But as a little free-form text box on the commitfest,
> it
> > > would be handy.
> > >
> > > One risk is that if we start to rely too much on that, or on the other
> > > fields in the commitfest app for that matter, we de-value the mailing
> > > list archives. I'm not too worried about it, the idea is that the
> > > summary box just summarizes what's already been said on the mailing
> > > list, or is transient information like "I'll get to this tomorrow"
> > > that's not interesting to archive.
> >
> > We already have the annotations feature, which is kind of this.
>
> But annotations are bound to mails in attached mail threads, rather
> than a generic text input at the CF entry level. There isn't always an
> appropriate link between (mail or in-person) conversations about the
> patch, and a summary of that conversation.
>
> 
>
> The CommitFest App has several features, but contains little
> information about how we're expected to use it. To start addressing
> this limitation, I've just created a wiki page about the CFA [0], with
> a handbook section. Feel free to extend or update the information as
> appropriate; I've only added that information the best of my
> knowledge, so it may contain wrong, incomplete and/or inaccurate
> information.
>
> Kind regards,
>
> Matthias van de Meent
>
> [0] https://wiki.postgresql.org/wiki/CommitFest_App
>
>
>


Re: Use streaming read API in ANALYZE

2024-05-20 Thread Melanie Plageman
On Wed, May 15, 2024 at 2:18 PM Nazir Bilal Yavuz  wrote:
>
> On Mon, 29 Apr 2024 at 18:41, Nazir Bilal Yavuz  wrote:
> >
> > On Mon, 8 Apr 2024 at 04:21, Thomas Munro  wrote:
> > I wanted to discuss what will happen to this patch now that
> > 27bc1772fc8 is reverted. I am continuing this thread but I can create
> > another thread if you prefer so.
>
> 041b96802ef is discussed in the 'Table AM Interface Enhancements'
> thread [1]. The main problems discussed about this commit is that the
> read stream API is not pushed to the heap-specific code and, because
> of that, the other AM implementations need to use read streams. To
> push read stream API to the heap-specific code, it is pretty much
> required to pass BufferAccessStrategy and BlockSamplerData to the
> initscan().
>
> I am sharing the alternative version of this patch. The first patch
> just reverts 041b96802ef and the second patch is the alternative
> version.
>
> In this alternative version, the read stream API is not pushed to the
> heap-specific code, but it is controlled by the heap-specific code.
> The SO_USE_READ_STREAMS_IN_ANALYZE flag is introduced and set in the
> heap-specific code if the scan type is 'ANALYZE'. This flag is used to
> decide whether streaming API in ANALYZE will be used or not. If this
> flag is set, this means heap AMs and read stream API will be used. If
> it is not set, this means heap AMs will not be used and code falls
> back to the version before read streams.

Personally, I think the alternative version here is the best option
other than leaving what is in master. However, I would vote for
keeping what is in master because 1) where we are in the release
timeline and 2) the acquire_sample_rows() code, before streaming read,
was totally block-based anyway.

If we kept what was in master, do we need to document for table AMs
how to use read_stream_next_buffer() or can we assume they will look
at the heap AM implementation?

- Melanie




Re: Cleaning up perl code

2024-05-20 Thread Dagfinn Ilmari Mannsåker
Alexander Lakhin  writes:

> Hello hackers,
>
> Please look at a bunch of unused variables and a couple of other defects
> I found in the perl code, maybe you'll find them worth fixing:

Nice cleanup!  Did you use some static analysis tool, or did look for
them manually?  If I add [Variables::ProhibitUnusedVariables] to
src/tools/perlcheck/perlcriticrc, it finds a few more, see the attached
patch.

The scripts parsing errcodes.txt really should be refactored into using
a common module, but that's a patch for another day.

- ilmari

>From 6b096a39753338bb91add5fcf1ed963024e58c15 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Dagfinn=20Ilmari=20Manns=C3=A5ker?= 
Date: Mon, 20 May 2024 19:55:20 +0100
Subject: [PATCH] Prohibit unused variables

---
 src/pl/plpgsql/src/generate-plerrcodes.pl | 6 ++
 src/pl/plpython/generate-spiexceptions.pl | 6 ++
 src/pl/tcl/generate-pltclerrcodes.pl  | 6 ++
 src/tools/perlcheck/perlcriticrc  | 2 ++
 src/tools/pgindent/pgindent   | 2 +-
 5 files changed, 9 insertions(+), 13 deletions(-)

diff --git a/src/pl/plpgsql/src/generate-plerrcodes.pl b/src/pl/plpgsql/src/generate-plerrcodes.pl
index 1c662bc967..e969a4b33e 100644
--- a/src/pl/plpgsql/src/generate-plerrcodes.pl
+++ b/src/pl/plpgsql/src/generate-plerrcodes.pl
@@ -23,10 +23,8 @@
 	# Skip section headers
 	next if /^Section:/;
 
-	die unless /^([^\s]{5})\s+([EWS])\s+([^\s]+)(?:\s+)?([^\s]+)?/;
-
-	(my $sqlstate, my $type, my $errcode_macro, my $condition_name) =
-	  ($1, $2, $3, $4);
+	my ($type, $errcode_macro, $condition_name) =
+		/^[^\s]{5}\s+([EWS])\s+([^\s]+)(?:\s+)?([^\s]+)?/ or die;
 
 	# Skip non-errors
 	next unless $type eq 'E';
diff --git a/src/pl/plpython/generate-spiexceptions.pl b/src/pl/plpython/generate-spiexceptions.pl
index f0c5142be3..984017f212 100644
--- a/src/pl/plpython/generate-spiexceptions.pl
+++ b/src/pl/plpython/generate-spiexceptions.pl
@@ -23,10 +23,8 @@
 	# Skip section headers
 	next if /^Section:/;
 
-	die unless /^([^\s]{5})\s+([EWS])\s+([^\s]+)(?:\s+)?([^\s]+)?/;
-
-	(my $sqlstate, my $type, my $errcode_macro, my $condition_name) =
-	  ($1, $2, $3, $4);
+	my ($type, $errcode_macro, $condition_name) =
+		/^[^\s]{5}\s+([EWS])\s+([^\s]+)(?:\s+)?([^\s]+)?/ or die;
 
 	# Skip non-errors
 	next unless $type eq 'E';
diff --git a/src/pl/tcl/generate-pltclerrcodes.pl b/src/pl/tcl/generate-pltclerrcodes.pl
index fcac4d00a6..58eb6afefe 100644
--- a/src/pl/tcl/generate-pltclerrcodes.pl
+++ b/src/pl/tcl/generate-pltclerrcodes.pl
@@ -23,10 +23,8 @@
 	# Skip section headers
 	next if /^Section:/;
 
-	die unless /^([^\s]{5})\s+([EWS])\s+([^\s]+)(?:\s+)?([^\s]+)?/;
-
-	(my $sqlstate, my $type, my $errcode_macro, my $condition_name) =
-	  ($1, $2, $3, $4);
+	my ($type, $errcode_macro, $condition_name) =
+		/^[^\s]{5}\s+([EWS])\s+([^\s]+)(?:\s+)?([^\s]+)?/ or die;
 
 	# Skip non-errors
 	next unless $type eq 'E';
diff --git a/src/tools/perlcheck/perlcriticrc b/src/tools/perlcheck/perlcriticrc
index 4739e9f4f1..6053dfcc2a 100644
--- a/src/tools/perlcheck/perlcriticrc
+++ b/src/tools/perlcheck/perlcriticrc
@@ -15,6 +15,8 @@ verbose = %f: %m at line %l, column %c.  %e.  ([%p] Severity: %s)\n
 
 # Note: for policy descriptions see https://metacpan.org/dist/Perl-Critic
 
+[Variables::ProhibitUnusedVariables]
+severity = 5
 
 # allow octal constants with leading zeros
 [-ValuesAndExpressions::ProhibitLeadingZeros]
diff --git a/src/tools/pgindent/pgindent b/src/tools/pgindent/pgindent
index 48d83bc434..063ec8ce63 100755
--- a/src/tools/pgindent/pgindent
+++ b/src/tools/pgindent/pgindent
@@ -22,7 +22,7 @@ my $indent_opts =
 my $devnull = File::Spec->devnull;
 
 my ($typedefs_file, $typedef_str, @excludes,
-	$indent, $build, $diff,
+	$indent, $diff,
 	$check, $help, @commits,);
 
 $help = 0;
-- 
2.39.2



Re: libpq compression (part 3)

2024-05-20 Thread Magnus Hagander
On Mon, May 20, 2024 at 9:09 PM Andrey M. Borodin 
wrote:

>
>
>
> > On 20 May 2024, at 23:37, Robert Haas  wrote:
> >
> > But, does this mean that we should just refuse to offer compression as
> > a feature?
>
> No, absolutely, we need the feature.
>
> > I guess I don't understand why TLS removed
> > support for encryption entirely instead of disclaiming its use in some
> > appropriate way.
>
> I think, the scope of TLS is too broad. HTTPS in turn has a compression.
> But AFAIK it never compress headers.
> IMO we should try to avoid compressing authentication information.
>

That used to be the case in HTTP/1. But header compression was one of the
headline features of HTTP/2, which isn't exactly new anymore. But there's a
special algorithm, HPACK, for it. And then http/3 uses QPACK.
Cloudflare has a pretty decent blog post explaining why and how:
https://blog.cloudflare.com/hpack-the-silent-killer-feature-of-http-2/, or
rfc7541 for all the details.

tl;dr; is yes, let's be careful not to expose headers to a CRIME-style
attack. And I doubt our connections has as much to gain by compressing
"header style" fields as http, so we are probably better off just not
compressing those parts.

-- 
 Magnus Hagander
 Me: https://www.hagander.net/ 
 Work: https://www.redpill-linpro.com/ 


Re: libpq compression (part 3)

2024-05-20 Thread Jacob Champion
On Mon, May 20, 2024 at 11:37 AM Robert Haas  wrote:
> But if that's a practical
> attack, preventing compression prior to the authentication exchange
> probably isn't good enough

I mean... you said it, not me. I'm trying not to rain on the parade
too much, because compression is clearly very valuable. But it makes
me really uncomfortable that we're reintroducing the compression
oracle (especially over the authentication exchange, which is
generally more secret than the rest of the traffic).

> But, does this mean that we should just refuse to offer compression as
> a feature? This kind of attack isn't a threat in every environment,
> and in some environments, compression could be pretty useful. For
> instance, you might need to pull down a lot of data from the database
> over a slow connection. Perhaps you're the only user of the database,
> and you wrote all of the queries yourself in a locked vault, accepting
> no untrusted inputs. In that case, these kinds of attacks aren't
> possible, or at least I don't see how, but you might want both
> compression and encryption.

Right, I think it's reasonable to let a sufficiently
determined/informed user lift the guardrails, but first we have to
choose to put guardrails in place... and then we have to somehow
sufficiently inform the users when it's okay to lift them.

> I guess I don't understand why TLS removed
> support for encryption entirely instead of disclaiming its use in some
> appropriate way.

One of the IETF conversations was at [1] (there were dissenters on the
list, as you might expect). My favorite summary is this one from
Alyssa Rowan:

> Compression is usually best performed as "high" as possible; transport layer 
> is blind to what's being compressed, which is (as we now know) was definitely 
> too low and was in retrospect a mistake.
>
> Any application layer protocol needs to know - if compression is supported - 
> to separate compression contexts for attacker-chosen plaintext and 
> attacker-sought unknown secrets. (As others have stated, HTTPbis covers this.)

But for SQL, where's the dividing line between attacker-chosen and
attacker-sought? To me, it seems like only the user knows; the server
has no clue. I think that puts us "lower" in Alyssa's model than HTTP
is.

As Andrey points out, there was prior work done that started to take
this into account. I haven't reviewed it to see how good it is -- and
I think there are probably many use cases in which queries and tables
contain both private and attacker-controlled information -- but if we
agree that they have to be separated, then the strategy can at least
be improved upon.

--Jacob

[1] https://mailarchive.ietf.org/arch/msg/tls/xhMLf8j4pq8W_ZGXUUU1G_m6r1c/




Re: libpq compression (part 3)

2024-05-20 Thread Jacob Champion
On Mon, May 20, 2024 at 11:05 AM Andrey M. Borodin  wrote:
> > So, the data would be compressed first, with framing around that, and
> > then transport encryption would happen afterwards. I don't see how
> > that would leak your password, but I have a feeling that might be a
> > sign that I'm about to learn some unpleasant truths.
>
> Compression defeats encryption. That's why it's not in TLS anymore.
> The thing is compression codecs use data self correlation. And if you mix 
> secret data with user's data, user might guess how correlated they are.

I'm slow on the draw, but I hacked up a sample client to generate
traffic against the compression-enabled server, to try to illustrate.

If my client sends an LDAP password of "hello", followed by the query
`SELECT 'world'`, as part of the same gzip stream, I get two encrypted
packets on the wire: lengths 42 and 49 bytes. If the client instead
sends the query `SELECT 'hello'`, I get lengths 42 and 46. We lost
three bytes, and there's only been one packet on the stream before the
query; if the observer controlled the query, it's pretty obvious that
the self-similarity has to have come from the PasswordMessage. Rinse
and repeat.

That doesn't cover the case where the password itself is low-entropy,
either. "hellohellohellohello" at least has length, but once you
compress it that collapses. So an attacker can passively monitor for
shorter password packets and know which user to target first.

--Jacob




Re: libpq compression (part 3)

2024-05-20 Thread Andrey M. Borodin




> On 20 May 2024, at 23:37, Robert Haas  wrote:
> 
>  But if that's a practical
> attack, preventing compression prior to the authentication exchange
> probably isn't good enough: the user could also try to guess what
> queries are being sent on behalf of other users through the same
> pooled connection, or they could try to use the bits of the query that
> they can control to guess what the other bits of the query that they
> can't see look like.

All these attacks can be practically exploited in a controlled environment.
That's why previous incarnation of this patchset [0] contained a way to reset 
compression context. And Odyssey AFAIR did it (Dan, coauthor of that patch, 
implemented the compression in Odyssey).
But attacking authentication is much more straightforward and viable.

> On 20 May 2024, at 23:37, Robert Haas  wrote:
> 
> But, does this mean that we should just refuse to offer compression as
> a feature?

No, absolutely, we need the feature.

> I guess I don't understand why TLS removed
> support for encryption entirely instead of disclaiming its use in some
> appropriate way.

I think, the scope of TLS is too broad. HTTPS in turn has a compression. But 
AFAIK it never compress headers.
IMO we should try to avoid compressing authentication information.


Best regards, Andrey Borodin.

[0] https://commitfest.postgresql.org/38/3499/



Re: First draft of PG 17 release notes

2024-05-20 Thread Jeff Davis
On Sat, 2024-05-18 at 17:51 -0400, Bruce Momjian wrote:
> Okay, I went with the attached applied patch.  Adjustments?

I think it should have more emphasis on the actual new feature: a
platform-independent builtin collation provider and the C.UTF-8 locale.

The user can look at the documentation for comparison with libc.

Regards,
Jeff Davis





Re: First draft of PG 17 release notes

2024-05-20 Thread Melanie Plageman
On Mon, May 20, 2024 at 9:37 AM Bruce Momjian  wrote:
>
> On Mon, May 20, 2024 at 01:23:02PM +0700, John Naylor wrote:
> > Hi Bruce, thanks for doing this again!
> >
> > I'm a bit late to this discussion -- there's been a bit of churn in
> > the vacuum items, and some streams got crossed along the way. I've
> > attached an attempt to rectify this.
>
> Agreed, patch applied, thanks.

If "Allow vacuum to more efficiently remove and freeze tuples" stays
in the release notes, I would add Heikki's name. He wasn't listed as a
co-author on all of the commits that were part of this feature, but he
made a substantial investment in it and should be listed, IMO. Patch
attached.

- Melanie
From 6f8c775a45ef90a3882d3d2f3c484fc82f9c072a Mon Sep 17 00:00:00 2001
From: Melanie Plageman 
Date: Mon, 20 May 2024 14:44:41 -0400
Subject: [PATCH v1] doc PG 17 relnotes:  add vacuum item author

Reported-by: Melanie Plageman
---
 doc/src/sgml/release-17.sgml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/doc/src/sgml/release-17.sgml b/doc/src/sgml/release-17.sgml
index 612eb100a7b..3025f31f8a0 100644
--- a/doc/src/sgml/release-17.sgml
+++ b/doc/src/sgml/release-17.sgml
@@ -498,7 +498,7 @@ Author: Heikki Linnakangas 
 
 
 
-Allow vacuum to more efficiently remove and freeze tuples (Melanie Plageman)
+Allow vacuum to more efficiently remove and freeze tuples (Melanie Plageman, Heikki Linnakangas)
 
 
 
-- 
2.34.1



Re: First draft of PG 17 release notes

2024-05-20 Thread Bruce Momjian
On Mon, May 20, 2024 at 02:35:37PM -0400, Melanie Plageman wrote:
> On Sat, May 18, 2024 at 11:13 AM Bruce Momjian  wrote:
> > Please see the email I just posted.  There are three goals we have to
> > adjust for:
> >
> > 1.  short release notes so they are readable
> > 2.  giving people credit for performance improvements
> > 3.  showing people Postgres cares about performance
> 
> I agree with all three of these goals. I would even add to 3 "show
> users Postgres is addressing their performance complaints". That in
> particular makes me less excited about having a  "generic performance
> release note item saying performance has been improved in the
> following areas" (from your other email). I think that describing the
> specific performance improvements is required to 1) allow users to
> change expectations and configurations to take advantage of the
> performance enhancements 2) ensure users know that their performance
> concerns are being addressed.

Well, as you can see, doing #2 & #3 works against accomplishing #1.

> > I would like to achieve 2 & 3 without harming #1.  My experience is if I
> > am reading a long document, and I get to a section where I start to
> > wonder, "Why should I care about this?", I start to skim the rest of
> > the document.  I am particularly critical if I start to wonder, "Why
> > does the author _think_ I should care about this?" becasue it feels like
> > the author is writing for him/herself and not the audience.
> 
> I see what you are saying. We don't want to just end up with the whole
> git log in the release notes. However, we know that not all users will
> care about the same features. As someone said somewhere else in this
> thread, presumably hackers spend time on features because some users
> want them.

I think we need as a separate section about performance improvements
that don't affect specific workloads.  Peter Eisentraut created an
Acknowledgements section at the bottom of the release notes, similar to
#2 above, so maybe someone else can add a performance internals section
too.

-- 
  Bruce Momjian  https://momjian.us
  EDB  https://enterprisedb.com

  Only you can decide what is important to you.




Re: libpq compression (part 3)

2024-05-20 Thread Robert Haas
On Mon, May 20, 2024 at 2:05 PM Andrey M. Borodin  wrote:
> Compression defeats encryption. That's why it's not in TLS anymore.
> The thing is compression codecs use data self correlation. And if you mix 
> secret data with user's data, user might guess how correlated they are.

Yeah, I'm aware that there are some problems like this. For example,
suppose the bad guy can both supply some of the data sent over the
connection (e.g. by typing search queries into a web page) and also
observe the traffic between the web application and the database. Then
they could supply data and try to guess how correlated that is with
other data sent over the same connection. But if that's a practical
attack, preventing compression prior to the authentication exchange
probably isn't good enough: the user could also try to guess what
queries are being sent on behalf of other users through the same
pooled connection, or they could try to use the bits of the query that
they can control to guess what the other bits of the query that they
can't see look like.

But, does this mean that we should just refuse to offer compression as
a feature? This kind of attack isn't a threat in every environment,
and in some environments, compression could be pretty useful. For
instance, you might need to pull down a lot of data from the database
over a slow connection. Perhaps you're the only user of the database,
and you wrote all of the queries yourself in a locked vault, accepting
no untrusted inputs. In that case, these kinds of attacks aren't
possible, or at least I don't see how, but you might want both
compression and encryption. I guess I don't understand why TLS removed
support for encryption entirely instead of disclaiming its use in some
appropriate way.

--
Robert Haas
EDB: http://www.enterprisedb.com




Re: First draft of PG 17 release notes

2024-05-20 Thread Melanie Plageman
On Sat, May 18, 2024 at 11:13 AM Bruce Momjian  wrote:
>
> On Thu, May 16, 2024 at 09:09:11AM -0400, Melanie Plageman wrote:
> > On Wed, May 15, 2024 at 11:48 PM Andres Freund  wrote:
> > >
> > > On 2024-05-15 10:38:20 +0200, Alvaro Herrera wrote:
> > > > I disagree with this.  IMO the impact of the Sawada/Naylor change is
> > > > likely to be enormous for people with large tables and large numbers of
> > > > tuples to clean up (I know we've had a number of customers in this
> > > > situation, I can't imagine any Postgres service provider that doesn't).
> > > > The fact that maintenance_work_mem is no longer capped at 1GB is very
> > > > important and I think we should mention that explicitly in the release
> > > > notes, as setting it higher could make a big difference in vacuum run
> > > > times.
> > >
> > > +many.
> > >
> > > We're having this debate every release. I think the ongoing reticence to 
> > > note
> > > performance improvements in the release notes is hurting Postgres.
> > >
> > > For one, performance improvements are one of the prime reason users
> > > upgrade. Without them being noted anywhere more dense than the commit log,
> > > it's very hard to figure out what improved for users. A halfway widely
> > > applicable performance improvement is far more impactful than many of the
> > > feature changes we do list in the release notes.
> >
> > The practical reason this matters to users is that they want to change
> > their configuration or expectations in response to performance
> > improvements.
> >
> > And also, as Jelte mentions upthread, describing performance
> > improvements made each release in Postgres makes it clear that we are
> > consistently improving it.
> >
> > > For another, it's also very frustrating for developers that focus on
> > > performance. The reticence to note their work, while noting other, far
> > > smaller, things in the release notes, pretty much tells us that our work 
> > > isn't
> > > valued.
> >
> > +many
>
> Please see the email I just posted.  There are three goals we have to
> adjust for:
>
> 1.  short release notes so they are readable
> 2.  giving people credit for performance improvements
> 3.  showing people Postgres cares about performance

I agree with all three of these goals. I would even add to 3 "show
users Postgres is addressing their performance complaints". That in
particular makes me less excited about having a  "generic performance
release note item saying performance has been improved in the
following areas" (from your other email). I think that describing the
specific performance improvements is required to 1) allow users to
change expectations and configurations to take advantage of the
performance enhancements 2) ensure users know that their performance
concerns are being addressed.

> I would like to achieve 2 & 3 without harming #1.  My experience is if I
> am reading a long document, and I get to a section where I start to
> wonder, "Why should I care about this?", I start to skim the rest of
> the document.  I am particularly critical if I start to wonder, "Why
> does the author _think_ I should care about this?" becasue it feels like
> the author is writing for him/herself and not the audience.

I see what you are saying. We don't want to just end up with the whole
git log in the release notes. However, we know that not all users will
care about the same features. As someone said somewhere else in this
thread, presumably hackers spend time on features because some users
want them.

- Melanie




Re: libpq compression (part 3)

2024-05-20 Thread Andrey M. Borodin



> On 20 May 2024, at 22:48, Robert Haas  wrote:
> 
> On Mon, May 20, 2024 at 1:23 PM Jacob Champion
>  wrote:
>> On Mon, May 20, 2024 at 10:01 AM Robert Haas  wrote:
>>> I really hope that you can't poke big enough holes to kill the feature
>>> entirely, though. Because that sounds sad.
>> 
>> Even if there are holes, I don't think the situation's going to be bad
>> enough to tank everything; otherwise no one would be able to use
>> decompression on the Internet. :D And I expect the authors of the
>> newer compression methods to have thought about these things [1].
>> 
>> I hesitate to ask as part of the same email, but what were the plans
>> for compression in combination with transport encryption? (Especially
>> if you plan to compress the authentication exchange, since mixing your
>> LDAP password into the compression context seems like it might be a
>> bad idea if you don't want to leak it.)
> 
> So, the data would be compressed first, with framing around that, and
> then transport encryption would happen afterwards. I don't see how
> that would leak your password, but I have a feeling that might be a
> sign that I'm about to learn some unpleasant truths.

Compression defeats encryption. That's why it's not in TLS anymore.
The thing is compression codecs use data self correlation. And if you mix 
secret data with user's data, user might guess how correlated they are.


Best regards, Andrey Borodin.



Re: libpq compression (part 3)

2024-05-20 Thread Robert Haas
On Mon, May 20, 2024 at 1:23 PM Jacob Champion
 wrote:
> On Mon, May 20, 2024 at 10:01 AM Robert Haas  wrote:
> > I really hope that you can't poke big enough holes to kill the feature
> > entirely, though. Because that sounds sad.
>
> Even if there are holes, I don't think the situation's going to be bad
> enough to tank everything; otherwise no one would be able to use
> decompression on the Internet. :D And I expect the authors of the
> newer compression methods to have thought about these things [1].
>
> I hesitate to ask as part of the same email, but what were the plans
> for compression in combination with transport encryption? (Especially
> if you plan to compress the authentication exchange, since mixing your
> LDAP password into the compression context seems like it might be a
> bad idea if you don't want to leak it.)

So, the data would be compressed first, with framing around that, and
then transport encryption would happen afterwards. I don't see how
that would leak your password, but I have a feeling that might be a
sign that I'm about to learn some unpleasant truths.

-- 
Robert Haas
EDB: http://www.enterprisedb.com




Re: soliciting patches to review

2024-05-20 Thread Robert Haas
On Tue, Apr 23, 2024 at 1:27 PM Robert Haas  wrote:
> Just a quick update. We have so far had 8 suggested patches from 6
> people, if I haven't missed anything. I'm fairly certain that not all
> of those patches are going to be good candidates for this session, so
> it would be great if a few more people wanted to volunteer their
> patches.

With approximately 1 week to go, I now have a list of 24 patches that
I think are good candidates for this session and another 11 that were
suggested but which I think are not good candidates for various
reasons, including (1) being trivial, (2) being so complicated that
it's not reasonable to review them in the time we'll have, and (3)
patching something other than the C code, which I consider too
specialized for this session.

I think that's a long enough list that we probably won't get to all of
the patches in the session, so I don't necessarily *need* more things
to put on the list at this point. However, I am still accepting
further nominations until approximately this time on Friday. Hence, if
you have written a patch that you think would be a good candidate for
some folks to review in their effort to become better reviewers, let
me (and Andres) know.

Thanks,

-- 
Robert Haas
EDB: http://www.enterprisedb.com




Re: libpq compression (part 3)

2024-05-20 Thread Jacob Champion
On Mon, May 20, 2024 at 10:01 AM Robert Haas  wrote:
> I really hope that you can't poke big enough holes to kill the feature
> entirely, though. Because that sounds sad.

Even if there are holes, I don't think the situation's going to be bad
enough to tank everything; otherwise no one would be able to use
decompression on the Internet. :D And I expect the authors of the
newer compression methods to have thought about these things [1].

I hesitate to ask as part of the same email, but what were the plans
for compression in combination with transport encryption? (Especially
if you plan to compress the authentication exchange, since mixing your
LDAP password into the compression context seems like it might be a
bad idea if you don't want to leak it.)

--Jacob

[1] https://datatracker.ietf.org/doc/html/rfc8878#name-security-considerations




Re: Propagate sanity checks of ProcessUtility() to standard_ProcessUtility()?

2024-05-20 Thread Robert Haas
On Fri, May 17, 2024 at 10:11 PM Michael Paquier  wrote:
> On Fri, May 17, 2024 at 03:53:58PM -0400, Robert Haas wrote:
> > The usual pattern for using hooks like this is to call the next
> > implementation, or the standard implementation, and pass down the
> > arguments that you got. If you try to do that and mess it up, you're
> > going to get a crash really, really quickly and it shouldn't be very
> > difficult at all to figure out what you did wrong. Honestly, that
> > doesn't seem like it would be hard even without the assertions: for
> > the most part, a quick glance at the stack backtrace ought to be
> > enough. If you're trying to do something more sophisticated, like
> > mutating the node tree before passing it down, the chances of your
> > mistakes getting caught by these assertions are pretty darn low, since
> > they're very superficial checks.
>
> Perhaps, still that would be something.
>
> Hmm.  We've had in the past bugs where DDL paths were playing with the
> manipulation of Querys in core, corrupting their contents.  It seems
> like what you would mean is to have a check at the *end* of
> ProcessUtility() that does an equalFuncs() on the Query, comparing it
> with a copy of it taken at its beginning, all that hidden within two
> USE_ASSERT_CHECKING blocks, when we'd expect the tree to not change.
> With readOnlyTree, that would be just changing from one policy to
> another, which is not really interesting at this stage based on how
> ProcessUtility() is shaped.

I don't think I meant to imply that. I think what I feel is that
there's no real problem here, and that the patch sort of superficially
looks useful, but isn't really. I'd suggest just dropping it.

-- 
Robert Haas
EDB: http://www.enterprisedb.com




Re: pg_combinebackup does not detect missing files

2024-05-20 Thread Robert Haas
On Fri, May 17, 2024 at 6:14 PM David Steele  wrote:
> Then intentionally corrupt a file in the incr backup:
>
> $ truncate -s 0 test/backup/incr1/base/5/3764_fsm
>
> In this case pg_verifybackup will error:
>
> $ pg_verifybackup test/backup/incr1
> pg_verifybackup: error: "base/5/3764_fsm" has size 0 on disk but size
> 24576 in the manifest
>
> But pg_combinebackup does not complain:
>
> $ pg_combinebackup test/backup/full test/backup/incr1 -o test/backup/combine
> $ ls -lah test/backup/combine/base/5/3764_fsm
> -rw--- 1 dev dialout 0 May 17 22:08 test/backup/combine/base/5/3764_fsm
>
> It would be nice if pg_combinebackup would (at least optionally but
> prefferrably by default) complain in this case rather than the user
> needing to separately run pg_verifybackup.

My first reaction here is that it would be better to have people run
pg_verifybackup for this. If we try to do this in pg_combinebackup,
we're either going to be quite limited in the amount of validation we
can do (which might lure users into a false sense of security) or
we're going to make things quite a bit more complicated and expensive.

Perhaps there's something here that is worth doing; I haven't thought
about this deeply and can't really do so at present. I do believe in
reasonable error detection, which I hope goes without saying, but I
also believe strongly in orthogonality: a tool should do one job and
do it as well as possible.

-- 
Robert Haas
EDB: http://www.enterprisedb.com




Re: libpq compression (part 3)

2024-05-20 Thread Robert Haas
On Mon, May 20, 2024 at 12:49 PM Jacob Champion
 wrote:
> ...and my response was that, no, the proposal doesn't seem to be
> requiring that authentication take place before compression is done.
> (As evidenced by your email. :D) If the claim is that there are no
> security problems with letting unauthenticated clients force
> decompression, then I can try to poke holes in that;

I would prefer this approach, so I suggest trying to poke holes here
first. If you find big enough holes then...

> or if the claim
> is that we don't need to worry about that at all because we'll wait
> until after authentication, then I can poke holes in that too. My
> request is just that we choose one.

...we can fall back to this and you can try to poke holes here.

I really hope that you can't poke big enough holes to kill the feature
entirely, though. Because that sounds sad.

-- 
Robert Haas
EDB: http://www.enterprisedb.com




Cleaning up perl code

2024-05-20 Thread Alexander Lakhin

Hello hackers,

Please look at a bunch of unused variables and a couple of other defects
I found in the perl code, maybe you'll find them worth fixing:
contrib/amcheck/t/001_verify_heapam.pl
$result # unused since introduction in 866e24d47
unused sub:
get_toast_for # not used since 860593ec3

contrib/amcheck/t/002_cic.pl
$result # orphaned since 7f580aa5d

src/backend/utils/activity/generate-wait_event_types.pl
$note, $note_name # unused since introduction in fa8892847

src/bin/pg_dump/t/003_pg_dump_with_server.pl
$cmd, $stdout, $stderr, $result # unused since introduction in 2f9eb3132

src/bin/pg_dump/t/005_pg_dump_filterfile.pl
$cmd, $stdout, $stderr, $result # unused since introduciton in a5cf808be

src/test/modules/ldap_password_func/t/001_mutated_bindpasswd.pl
$slapd, $ldap_schema_dir # unused since introduction in 419a8dd81

src/test/modules/ssl_passphrase_callback/t/001_testfunc.pl
$clearpass # orphaned since b846091fd

src/test/perl/PostgreSQL/Test/AdjustUpgrade.pm
$ostmt # unused since introduction in 47bb9db75

src/test/recovery/t/021_row_visibility.pl
$ret # unused since introduction in 7b28913bc

src/test/recovery/t/032_relfilenode_reuse.pl
$ret # unused since introduction in e2f65f425

src/test/recovery/t/035_standby_logical_decoding.pl
$stdin, $ret, $slot # unused since introduction in fcd77d532
$subscriber_stdin, $subscriber_stdout, $subscriber_stderr # unused since 
introduction in 376dc8205

src/test/subscription/t/024_add_drop_pub.pl
invalid reference in a comment:
tab_drop_refresh -> tab_2 # introduced with 1046a69b3
(invalid since v6-0001-...patch in the commit's thread)

src/tools/msvc_gendef.pl
@def # unused since introduction in 933b46644?

I've attached a patch with all of these changes (tested with meson build
on Windows and check-world on Linux).

Best regards,
Alexanderdiff --git a/contrib/amcheck/t/001_verify_heapam.pl b/contrib/amcheck/t/001_verify_heapam.pl
index 9de3148277..481e4dbe4f 100644
--- a/contrib/amcheck/t/001_verify_heapam.pl
+++ b/contrib/amcheck/t/001_verify_heapam.pl
@@ -9,7 +9,7 @@ use PostgreSQL::Test::Utils;
 
 use Test::More;
 
-my ($node, $result);
+my $node;
 
 #
 # Test set-up
@@ -87,19 +87,6 @@ sub relation_filepath
 	return "$pgdata/$rel";
 }
 
-# Returns the fully qualified name of the toast table for the named relation
-sub get_toast_for
-{
-	my ($relname) = @_;
-
-	return $node->safe_psql(
-		'postgres', qq(
-		SELECT 'pg_toast.' || t.relname
-			FROM pg_catalog.pg_class c, pg_catalog.pg_class t
-			WHERE c.relname = '$relname'
-			  AND c.reltoastrelid = t.oid));
-}
-
 # (Re)create and populate a test table of the given name.
 sub fresh_test_table
 {
diff --git a/contrib/amcheck/t/002_cic.pl b/contrib/amcheck/t/002_cic.pl
index 53a3db9745..0207407ca0 100644
--- a/contrib/amcheck/t/002_cic.pl
+++ b/contrib/amcheck/t/002_cic.pl
@@ -10,7 +10,7 @@ use PostgreSQL::Test::Utils;
 
 use Test::More;
 
-my ($node, $result);
+my $node;
 
 #
 # Test set-up
diff --git a/src/backend/utils/activity/generate-wait_event_types.pl b/src/backend/utils/activity/generate-wait_event_types.pl
index 42f36f405b..b2d61bd8ba 100644
--- a/src/backend/utils/activity/generate-wait_event_types.pl
+++ b/src/backend/utils/activity/generate-wait_event_types.pl
@@ -42,8 +42,6 @@ my @abi_compatibility_lines;
 my @lines;
 my $abi_compatibility = 0;
 my $section_name;
-my $note;
-my $note_name;
 
 # Remove comments and empty lines and add waitclassname based on the section
 while (<$wait_event_names>)
diff --git a/src/bin/pg_dump/t/003_pg_dump_with_server.pl b/src/bin/pg_dump/t/003_pg_dump_with_server.pl
index b5a1445550..3f549f44e7 100644
--- a/src/bin/pg_dump/t/003_pg_dump_with_server.pl
+++ b/src/bin/pg_dump/t/003_pg_dump_with_server.pl
@@ -26,7 +26,6 @@ $node->safe_psql('postgres', "CREATE SERVER s1 FOREIGN DATA WRAPPER dummy");
 $node->safe_psql('postgres', "CREATE SERVER s2 FOREIGN DATA WRAPPER dummy");
 $node->safe_psql('postgres', "CREATE FOREIGN TABLE t0 (a int) SERVER s0");
 $node->safe_psql('postgres', "CREATE FOREIGN TABLE t1 (a int) SERVER s1");
-my ($cmd, $stdout, $stderr, $result);
 
 command_fails_like(
 	[ "pg_dump", '-p', $port, '--include-foreign-data=s0', 'postgres' ],
diff --git a/src/bin/pg_dump/t/005_pg_dump_filterfile.pl b/src/bin/pg_dump/t/005_pg_dump_filterfile.pl
index a80e13a0d3..6025bb296c 100644
--- a/src/bin/pg_dump/t/005_pg_dump_filterfile.pl
+++ b/src/bin/pg_dump/t/005_pg_dump_filterfile.pl
@@ -81,7 +81,6 @@ $node->safe_psql('sourcedb',
 #
 # Test interaction of correctly specified filter file
 #
-my ($cmd, $stdout, $stderr, $result);
 
 # Empty filterfile
 open $inputfile, '>', "$tempdir/inputfile.txt"
diff --git a/src/test/modules/ldap_password_func/t/001_mutated_bindpasswd.pl b/src/test/modules/ldap_password_func/t/001_mutated_bindpasswd.pl
index b990e7d101..82b1cb88e9 100644
--- a/src/test/modules/ldap_password_func/t/001_mutated_bindpasswd.pl
+++ b/src/test/modules/ldap_password_func/t/001_mutated_bindpasswd.pl
@@ -12,10 +12,6 @@ use Test::More;
 

Re: libpq compression (part 3)

2024-05-20 Thread Jacob Champion
On Mon, May 20, 2024 at 8:29 AM Robert Haas  wrote:
> It does occur to me that if some compression algorithm has a buffer
> overrun bug, restricting its use until after authentication might
> reduce the score of the resulting CVE, because now you have to be able
> to authenticate to make an exploit work. Perhaps that's an argument
> for imposing a restriction here, but it doesn't seem to be the
> argument that you're making.

It wasn't my argument; Jacob B said above:

> in general postgres servers are usually connected to by
> clients that the server admin has some channel to talk to (after all
> they somehow had to get access to log in to the server in the first
> place) if they are doing something wasteful, given that a client can
> do a lot worse things than enable aggressive compression by writing
> bad queries.

...and my response was that, no, the proposal doesn't seem to be
requiring that authentication take place before compression is done.
(As evidenced by your email. :D) If the claim is that there are no
security problems with letting unauthenticated clients force
decompression, then I can try to poke holes in that; or if the claim
is that we don't need to worry about that at all because we'll wait
until after authentication, then I can poke holes in that too. My
request is just that we choose one.

> But if the client says in the startup message that it would like to
> send and receive compressed data and the server is happy with that
> request, I don't see why we need to postpone implementing that request
> until after the authentication exchange is completed. I think that
> will make the code more complicated and I don't see a security
> benefit.

I haven't implemented compression bombs before to know lots of
details, but I think the general idea is to take up resources that are
vastly disproportionate to the effort expended by the client. The
systemic risk is then more or less multiplied by the number of
intermediaries that need to do the decompression. Maybe all three of
our algorithms are hardened against malicious compression techniques;
that'd be great. But if we've never had a situation where a completely
untrusted peer can hand a blob to the server and say "here, decompress
this for me", maybe we'd better check?

--Jacob




Re: PostgreSQL 17 Beta 1 release announcement draft

2024-05-20 Thread Jonathan S. Katz

On 5/20/24 6:32 AM, David Rowley wrote:

On Mon, 20 May 2024 at 22:11, Alvaro Herrera  wrote:


On 2024-May-16, David Rowley wrote:


On Thu, 16 May 2024 at 17:37, zaidagilist  wrote:

I am trying to open the 17 docs but it looks removed. Getting
following message "Page not found"

https://www.postgresql.org/docs/17/


It's called "devel" for "development" until we branch sometime before July:

https://www.postgresql.org/docs/devel/


Hmm, but that would mean that the Beta1 announce would ship full of
links that will remain broken until July.  I'm not sure what the
workflow for this is, but I hope the /17/ URLs would become valid with
beta1, later this week.


I didn't quite click that it was Jonathan's links that were being
complained about.

I don't know how the website picks up where to link the doc page for a
given version.  I see from e0b82fc8e8 that the PACKAGE_VERSION was
changed from 16devel to 16beta1. Does the website have something that
extracts "devel" from the former and "16" from the latter?  I see the
release announcement for 16beta1 had /16/ links per [1].  So, I guess
it works. I just don't know how.


The tl;dr is that the /17/ links will be available on release day. I've 
validated the current links using the /devel/ heading.


Jonathan



OpenPGP_signature.asc
Description: OpenPGP digital signature


Re: PostgreSQL 17 Beta 1 release announcement draft

2024-05-20 Thread Jonathan S. Katz

On 5/20/24 8:31 AM, jian he wrote:


release note (https://momjian.us/pgsql_docs/release-17.html)
is
"Add jsonpath methods to convert JSON values to other JSON data types
(Jeevan Chalke)"



Additionally, PostgreSQL 17 adds more functionality to its `jsonpath` 
implementation, including the ability to convert JSON values to different data 
types.

so, I am not sure this is 100% correct.

Maybe we can rephrase it like:


Additionally, PostgreSQL 17 adds more functionality to its `jsonpath` 
implementation, including the ability to convert JSON values to other JSON data 
types.


The release note goes on to state:

==
The jsonpath methods are .bigint(), .boolean(), .date(), 
.decimal([precision [, scale]]), .integer(), .number(), .string(), 
.time(), .time_tz(), .timestamp(), and .timestamp_tz().

==

And reviewing the docs[1], these are converted to a PostgreSQL native 
types, and not JSON types (additionally a bunch of those are not JSON 
types).


Jeevan: can you please confirm that this work converts into the 
PostgreSQL native types?


Thanks,

Jonathan

[1] https://www.postgresql.org/docs/devel/functions-json.html


OpenPGP_signature.asc
Description: OpenPGP digital signature


Re: Reading timestamp values from Datums gives garbage values

2024-05-20 Thread Tom Lane
Tomas Vondra  writes:
> On 5/20/24 16:37, Sushrut Shivaswamy wrote:
>> When trying to read the query response from the Datum, I get garbage values.
>> I've tried various types and none of them read the correct value.

> TimestampTz is int64, so using DatumGetInt64 is probably the simplest
> solution. And it's the number of microseconds, so X/1e6 should give you
> the epoch.

Don't forget that TimestampTz uses an epoch (time zero) of 2000-01-01.
If you want a Unix-convention value where the epoch is 1970-01-01,
you'll need to add 30 years to the result.

The reported values seem pretty substantially off, though ---
5293917674 would be barely an hour and a half later than the
epoch, which seems unlikely to be the value Sushrut intended
to test with.  I suspect a mistake that's outside the fragment
of code we were shown.

regards, tom lane




Re: Reading timestamp values from Datums gives garbage values

2024-05-20 Thread Chapman Flack
On 05/20/24 11:39, Tomas Vondra wrote:
> On 5/20/24 16:37, Sushrut Shivaswamy wrote:
>> I've tried various types and none of them read the correct value.
>> ```
>> ...
>> double current_time = DatumGetFloat8(current_timestamp); // prints 0
>>
>> int64 time = DatumGetUint64(current_timestamp); // prints 5293917674
>> ```
> 
> TimestampTz is int64, so using DatumGetInt64 is probably the simplest
> solution. And it's the number of microseconds, so X/1e6 should give you
> the epoch.

Indeed, the "Postgres epoch" is a fairly modern date (1 January 2000),
so a signed representation is needed to express earlier dates.

Possibly of interest for questions like these, some ongoing work in PL/Java
is to capture knowledge like this in simple Java functional interfaces
that are (intended to be) sufficiently clear and documented to serve as
a parallel source of reference matter.

For example, what's there for TimestampTZ:

https://tada.github.io/pljava/preview1.7/pljava-api/apidocs/org.postgresql.pljava/org/postgresql/pljava/adt/Datetime.TimestampTZ.html#method-detail

A separation of concerns is involved, where these functional interfaces
expose and document a logical structure and, ideally, whatever semantic
subtleties may be inherent in it, but not physical details of how those
bits might be shoehorned into the Datum. Physical layouts are encapsulated
in Adapter classes as internal details. TimeTZ is a good example:

https://tada.github.io/pljava/preview1.7/pljava-api/apidocs/org.postgresql.pljava/org/postgresql/pljava/adt/Datetime.TimeTZ.html#method-detail

It tells you of the µsSinceMidnight component, and secsWestOfPrimeMeridian
component, and the sign flip needed for other common representations of
zone offsets that are positive _east_ of the prime meridian. It doesn't
expose the exact layout of those components in a Datum.

For your purposes, of course, you need the physical layout details too,
most easily found by reading the PG source. But my hope is that this
parallel documentation of the logical structure may help in making
effective use of what you find there.

Regards,
-Chap




Re: date_trunc function in interval version

2024-05-20 Thread Przemysław Sztoch

Yasir wrote on 19.05.2024 00:03:


I would also like to thank Robert for presenting the matter in detail.

My function date_trunc ( interval, timestamp, ...) is similar to
original function date_trunc ( text, timestamp ...) .

My extension only gives more granularity.
We don't have a jump from hour to day. We can use 6h and 12h. It's
the same with minutes.
We can round to 30 minutes, 20minutes, 15 minutes, etc.

Using date_bin has a similar effect, but requires specifying the
origin. According to this origin,
subsequent buckets are then calculated. The need to provide this
origin is sometimes a very big problem.
Especially since you cannot use one origin when changing from
summer to winter time.

If we use one origin for example begin of year: 2024-01-01
00:00:00 then:
# SET timezone='Europe/Warsaw';
# SELECT date_bin('1 day', '2024-03-05 11:22:33', '2024-01-01
00:00:00'), date_trunc('day', '2024-03-05 11:22:33'::timestamptz);
2024-03-05 00:00:00+01 2024-03-05 00:00:00+01    date_bin works
ok, because we are before DST
# SELECT date_bin('1 day', '2024-05-05 11:22:33', '2024-01-01
00:00:00'), date_trunc('day', '2024-05-05 11:22:33'::timestamptz);
2024-05-05 01:00:00+02 2024-05-05 00:00:00+02    date_bin has
problem, because we are in May after DST

If anyone has an idea how to make date_bin work like date_trunc,
please provide an example.


Here is an example which will make date_bin() to behave like 
date_trunc():
# SELECT date_bin('1 day', '2024-05-05 11:22:33', 
'0001-01-01'::timestamp), date_trunc('day', '2024-05-05 
11:22:33'::timestamptz);

      date_bin       | date_trunc
-+
 2024-05-05 00:00:00 | 2024-05-05 00:00:00+02
(1 row)

In general, to make date_bin work similarly to date_trunc in 
PostgreSQL, you need to set the interval length appropriately and use 
an origin timestamp that aligns with the start of the interval you 
want to bin.


Here's how you can use date_bin to mimic the behavior of date_trunc:

Truncate to the Start of the Year:
# SELECT date_bin('1 year', timestamp_column, '0001-01-01'::timestamp) 
FROM your_table;

Truncate to the Start of the Month:
# SELECT date_bin('1 month', timestamp_column, 
'0001-01-01'::timestamp) FROM your_table;

Truncate to the Start of the Day:
# SELECT date_bin('1 day', timestamp_column, '0001-01-01'::timestamp) 
FROM your_table;

Truncate to the Start of the Hour:
# SELECT date_bin('1 hour', timestamp_column, '0001-01-01'::timestamp) 
FROM your_table;

Truncate to the Start of the Minute:
# SELECT date_bin('1 minute', timestamp_column, 
'0001-01-01'::timestamp) FROM your_table;



-- 
Przemysław Sztoch | Mobile +48 509 99 00 66



Please, use it with timestamptz for '2 hours' or '3 hours' interval.

SET timezone TO 'Europe/Warsaw';
SELECT ts,
   date_bin('1 hour'::interval, ts, '0001-01-01 00:00:00') AS 
one_hour_bin,
   date_bin('2 hour'::interval, ts, '0001-01-01 00:00:00') AS 
two_hours_bin,
   date_bin('3 hour'::interval, ts, '0001-01-01 00:00:00') AS 
three_hours_bin

   FROM generate_series('2022-03-26 21:00:00+00'::timestamptz,
    '2022-03-27 07:00:00+00'::timestamptz,
    '30 min'::interval,
    'Europe/Warsaw') AS ts;

   ts   |  one_hour_bin  | two_hours_bin  
|    three_hours_bin

+++
 2022-03-26 22:00:00+01 | 2022-03-26 21:36:00+01 | 2022-03-26 
21:36:00+01 | 2022-03-26 20:36:00+01
 2022-03-26 22:30:00+01 | 2022-03-26 21:36:00+01 | 2022-03-26 
21:36:00+01 | 2022-03-26 20:36:00+01
 2022-03-26 23:00:00+01 | 2022-03-26 22:36:00+01 | 2022-03-26 
21:36:00+01 | 2022-03-26 20:36:00+01
 2022-03-26 23:30:00+01 | 2022-03-26 22:36:00+01 | 2022-03-26 
21:36:00+01 | 2022-03-26 20:36:00+01
 2022-03-27 00:00:00+01 | 2022-03-26 23:36:00+01 | 2022-03-26 
23:36:00+01 | 2022-03-26 23:36:00+01
 2022-03-27 00:30:00+01 | 2022-03-26 23:36:00+01 | 2022-03-26 
23:36:00+01 | 2022-03-26 23:36:00+01
 2022-03-27 01:00:00+01 | 2022-03-27 00:36:00+01 | 2022-03-26 
23:36:00+01 | 2022-03-26 23:36:00+01
 2022-03-27 01:30:00+01 | 2022-03-27 00:36:00+01 | 2022-03-26 
23:36:00+01 | 2022-03-26 23:36:00+01
 2022-03-27 03:00:00+02 | 2022-03-27 01:36:00+01 | 2022-03-27 
01:36:00+01 | 2022-03-26 23:36:00+01
 2022-03-27 03:30:00+02 | 2022-03-27 01:36:00+01 | 2022-03-27 
01:36:00+01 | 2022-03-26 23:36:00+01
 2022-03-27 04:00:00+02 | 2022-03-27 03:36:00+02 | 2022-03-27 
01:36:00+01 | 2022-03-27 03:36:00+02
 2022-03-27 04:30:00+02 | 2022-03-27 03:36:00+02 | 2022-03-27 
01:36:00+01 | 2022-03-27 03:36:00+02
 2022-03-27 05:00:00+02 | 2022-03-27 04:36:00+02 | 2022-03-27 
04:36:00+02 | 2022-03-27 03:36:00+02
 2022-03-27 05:30:00+02 | 2022-03-27 04:36:00+02 | 2022-03-27 
04:36:00+02 | 2022-03-27 03:36:00+02
 2022-03-27 06:00:00+02 | 2022-03-27 

Re: commitfest.postgresql.org is no longer fit for purpose

2024-05-20 Thread Matthias van de Meent
On Fri, 17 May 2024 at 15:02, Peter Eisentraut  wrote:
>
> On 17.05.24 09:32, Heikki Linnakangas wrote:
> > Dunno about having to click a link or sparkly gold borders, but +1 on
> > having a free-form text box for notes like that. Things like "cfbot says
> > this has bitrotted" or "Will review this after other patch this depends
> > on". On the mailing list, notes like that are both noisy and easily lost
> > in the threads. But as a little free-form text box on the commitfest, it
> > would be handy.
> >
> > One risk is that if we start to rely too much on that, or on the other
> > fields in the commitfest app for that matter, we de-value the mailing
> > list archives. I'm not too worried about it, the idea is that the
> > summary box just summarizes what's already been said on the mailing
> > list, or is transient information like "I'll get to this tomorrow"
> > that's not interesting to archive.
>
> We already have the annotations feature, which is kind of this.

But annotations are bound to mails in attached mail threads, rather
than a generic text input at the CF entry level. There isn't always an
appropriate link between (mail or in-person) conversations about the
patch, and a summary of that conversation.



The CommitFest App has several features, but contains little
information about how we're expected to use it. To start addressing
this limitation, I've just created a wiki page about the CFA [0], with
a handbook section. Feel free to extend or update the information as
appropriate; I've only added that information the best of my
knowledge, so it may contain wrong, incomplete and/or inaccurate
information.

Kind regards,

Matthias van de Meent

[0] https://wiki.postgresql.org/wiki/CommitFest_App




Re: Speed up clean meson builds by ~25%

2024-05-20 Thread Robert Haas
On Mon, May 20, 2024 at 11:37 AM Andres Freund  wrote:
> On 2024-05-20 09:37:46 -0400, Robert Haas wrote:
> > On Sat, May 18, 2024 at 6:09 PM Andres Freund  wrote:
> > > A few tests with ccache disabled:
> >
> > These tests seem to show no difference between the two releases, so I
> > wonder what you're intending to demonstrate here.
>
> They show a few seconds of win for 'real' time.
> -O0: 0m21.577s->0m19.529s
> -O3: 0m59.730s->0m54.853s

Ah, OK, I think I misinterpreted.

-- 
Robert Haas
EDB: http://www.enterprisedb.com




Re: zlib detection in Meson on Windows broken?

2024-05-20 Thread Andrew Dunstan


On 2024-05-20 Mo 06:58, Dave Page wrote:

Hi

I'm working on updating the build of PostgreSQL that pgAdmin uses in 
its Windows installers to use Meson ready for the v17 release. I'm 
using Visual Studio 2022, on Windows Server 2022.


I've been unable to persuade Meson to detect zlib, whilst OpenSSL 
seems to be fine.


The dependencies have been built and installed as follows:

 mkdir c:\build64

 wget https://zlib.net/zlib-1.3.2.tar.gz
 tar -zxvf zlib-1.3.2.tar.gz
 cd zlib-1.3.2
 cmake -DCMAKE_INSTALL_PREFIX=C:/build64/zlib -G "Visual Studio 17 2022" .
 msbuild ALL_BUILD.vcxproj /p:Configuration=Release
 msbuild RUN_TESTS.vcxproj /p:Configuration=Release
 msbuild INSTALL.vcxproj /p:Configuration=Release
 cd ..

 wget https://www.openssl.org/source/openssl-3.0.13.tar.gz
 tar -zxvf openssl-3.0.13.tar.gz
 cd openssl-3.0.013
 perl Configure VC-WIN64A no-asm --prefix=C:\build64\openssl no-ssl3 
no-comp

 nmake
 nmake test
 nmake install
 cd ..

This results in the following headers and libraries being installed 
for zlib:


C:\Users\dpage\git\postgresql>dir C:\build64\zlib\include
 Volume in drive C has no label.
 Volume Serial Number is 3AAD-5864

 Directory of C:\build64\zlib\include

17/05/2024  15:56              .
17/05/2024  15:56              ..
17/05/2024  15:54            17,096 zconf.h
22/01/2024  19:32            96,829 zlib.h
               2 File(s)        113,925 bytes
               2 Dir(s)  98,842,726,400 bytes free

C:\Users\dpage\git\postgresql>dir C:\build64\zlib\lib
 Volume in drive C has no label.
 Volume Serial Number is 3AAD-5864

 Directory of C:\build64\zlib\lib

17/05/2024  17:01              .
17/05/2024  15:56              ..
17/05/2024  15:55            16,638 zlib.lib
17/05/2024  15:55           184,458 zlibstatic.lib
               2 File(s)        201,096 bytes
               2 Dir(s)  98,842,726,400 bytes free

I then attempt to build PostgreSQL:

 meson setup build 
-Dextra_include_dirs=C:/build64/openssl/include,C:/build64/zlib/include 
-Dextra_lib_dirs=C:/build64/openssl/lib,C:/build64/zlib/lib 
-Dssl=openssl -Dzlib=enabled --prefix=c:/build64/pgsql


Which results in the output in output.txt, indicating that OpenSSL was 
correctly found, but zlib was not. I've also attached the meson log.


I have very little experience with Meson, and even less interpreting 
it's logs, but it seems to me that it's not including the extra lib 
and include directories when it runs the test compile, given the 
command line it's reporting:


cl 
C:\Users\dpage\git\postgresql\build\meson-private\tmpg_h4xcue\testfile.c 
/nologo /showIncludes /utf-8 /EP /nologo /showIncludes /utf-8 /EP /Od /Oi-


Bug, or am I doing something silly?





Hi Dave!


Not sure ;-) But this works for the buildfarm animal drongo, so we 
should be able to make it work for you. I'll contact you offlist and see 
if I can help.



cheers


andrew

--
Andrew Dunstan
EDB:https://www.enterprisedb.com


Re: Reading timestamp values from Datums gives garbage values

2024-05-20 Thread Tomas Vondra
On 5/20/24 16:37, Sushrut Shivaswamy wrote:
> Hey,
> 
> I'm trying to read a timestamp column as EPOCH.
> My query is as follows.
> ```
> SELECT EXTRACT(EPOCH FROM timestamp_column) FROM table;
> 
> column
> --
> 
> 1716213097.86486
> ```
> When running in the console this query gives valid epoch output which
> appears to be of type double.
> 
> When trying to read the query response from the Datum, I get garbage values.
> I've tried various types and none of them read the correct value.
> ```
> 
> Datum current_timestamp = SPI_getbinval(SPI_tuptable->vals[i],
> SPI_tuptable->tupdesc, 5, );
> 
> double current_time = DatumGetFloat8(current_timestamp); // prints 0
> 
> int64 time = DatumGetUint64(current_timestamp); // prints 5293917674
> ```
> 

TimestampTz is int64, so using DatumGetInt64 is probably the simplest
solution. And it's the number of microseconds, so X/1e6 should give you
the epoch.

regards

-- 
Tomas Vondra
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company




Re: Speed up clean meson builds by ~25%

2024-05-20 Thread Andres Freund
On 2024-05-20 09:37:46 -0400, Robert Haas wrote:
> On Sat, May 18, 2024 at 6:09 PM Andres Freund  wrote:
> > A few tests with ccache disabled:
> 
> These tests seem to show no difference between the two releases, so I
> wonder what you're intending to demonstrate here.

They show a few seconds of win for 'real' time.
-O0: 0m21.577s->0m19.529s
-O3: 0m59.730s->0m54.853s




Re: libpq compression (part 3)

2024-05-20 Thread Robert Haas
On Mon, May 20, 2024 at 10:15 AM Jacob Champion
 wrote:
> This is just restating the "you can already do bad things" argument. I
> understand that if your query gets executed, it's going to consume
> resources on the thing that's executing it (for the record, though,
> there are people working on constraining that). But introducing
> disproportionate resource consumption into all traffic-inspecting
> software, like pools and bouncers, seems like a different thing to me.
> Many use cases are going to be fine with it, of course, but I don't
> think it should be hand-waved.

I can't follow this argument.

I think it's important that the startup message is always sent
uncompressed, because it's a strange exception to our usual
message-formatting rules, and because it's so security-critical. I
don't think we should do anything to allow more variation there,
because any benefit will be small and the chances of introducing
security vulnerabilities seems non-trivial.

But if the client says in the startup message that it would like to
send and receive compressed data and the server is happy with that
request, I don't see why we need to postpone implementing that request
until after the authentication exchange is completed. I think that
will make the code more complicated and I don't see a security
benefit. If the use of a particular compression algorithm is going to
impose too much load, the server, or the pooler, is free to refuse it,
and should. Deferring the use of the compression method until after
authentication doesn't really solve any problem here, at least not
that I can see.

It does occur to me that if some compression algorithm has a buffer
overrun bug, restricting its use until after authentication might
reduce the score of the resulting CVE, because now you have to be able
to authenticate to make an exploit work. Perhaps that's an argument
for imposing a restriction here, but it doesn't seem to be the
argument that you're making.

-- 
Robert Haas
EDB: http://www.enterprisedb.com




Re: libpq compression (part 3)

2024-05-20 Thread Robert Haas
On Sat, May 18, 2024 at 1:18 AM Jacob Burroughs
 wrote:
> I like this more than what I proposed, and will update the patches to
> reflect this proposal. (I've gotten them locally back into a state of
> applying cleanly and dealing with the changes needed to support direct
> SSL connections, so refactoring the protocol layer shouldn't be too
> hard now.)

Sounds good!

-- 
Robert Haas
EDB: http://www.enterprisedb.com




Re: Shared detoast Datum proposal

2024-05-20 Thread Robert Haas
Hi,

Andy Fan asked me off-list for some feedback about this proposal. I
have hesitated to comment on it for lack of having studied the matter
in any detail, but since I've been asked for my input, here goes:

I agree that there's a problem here, but I suspect this is not the
right way to solve it. Let's compare this to something like the
syscache. Specifically, let's think about the syscache on
pg_class.relname.

In the case of the syscache on pg_class.relname, there are two reasons
why we might repeatedly look up the same values in the cache. One is
that the code might do multiple name lookups when it really ought to
do only one. Doing multiple lookups is bad for security and bad for
performance, but we have code like that in some places and some of it
is hard to fix. The other reason is that it is likely that the user
will mention the same table names repeatedly; each time they do, they
will trigger a lookup on the same name. By caching the result of the
lookup, we can make it much faster. An important point to note here is
that the queries that the user will issue in the future are unknown to
us. In a certain sense, we cannot even know whether the same table
name will be mentioned more than once in the same query: when we reach
the first instance of the table name and look it up, we do not have
any good way of knowing whether it will be mentioned again later, say
due to a self-join. Hence, the pattern of cache lookups is
fundamentally unknowable.

But that's not the case in the motivating example that started this
thread. In that case, the target list includes three separate
references to the same column. We can therefore predict that if the
column value is toasted, we're going to de-TOAST it exactly three
times. If, on the other hand, the column value were mentioned only
once, it would be detoasted just once. In that latter case, which is
probably quite common, this whole cache idea seems like it ought to
just waste cycles, which makes me suspect that no matter what is done
to this patch, there will always be cases where it causes significant
regressions. In the former case, where the column reference is
repeated, it will win, but it will also hold onto the detoasted value
after the third instance of detoasting, even though there will never
be any more cache hits. Here, unlike the syscache case, the cache is
thrown away at the end of the query, so future queries can't benefit.
Even if we could find a way to preserve the cache in some cases, it's
not very likely to pay off. People are much more likely to hit the
same table more than once than to hit the same values in the same
table more than once in the same session.

Suppose we had a design where, when a value got detoasted, the
detoasted value went into the place where the toasted value had come
from. Then this problem would be handled pretty much perfectly: the
detoasted value would last until the scan advanced to the next row,
and then it would be thrown out. So there would be no query-lifespan
memory leak. Now, I don't really know how this would work, because the
TOAST pointer is coming out of a slot and we can't necessarily write
one attribute of any arbitrary slot type without a bunch of extra
overhead, but maybe there's some way. If it could be done cheaply
enough, it would gain all the benefits of this proposal a lot more
cheaply and with fewer downsides. Alternatively, maybe there's a way
to notice the multiple references and introduce some kind of
intermediate slot or other holding area where the detoasted value can
be stored.

In other words, instead of computing

big_jsonb_col->'a',  big_jsonb_col->'b',  big_jsonb_col->'c'

Maybe we ought to be trying to compute this:

big_jsonb_col=detoast(big_jsonb_col)
big_jsonb_col->'a',  big_jsonb_col->'b',  big_jsonb_col->'c'

Or perhaps this:

tmp=detoast(big_jsonb_col)
tmp->'a', tmp->'b', tmp->'c'

In still other words, a query-lifespan cache for this information
feels like it's tackling the problem at the wrong level. I do suspect
there may be query shapes where the same value gets detoasted multiple
times in ways that the proposals I just made wouldn't necessarily
catch, such as in the case of a self-join. But I think those cases are
rare. In most cases, repeated detoasting is probably very localized,
with the same exact TOAST pointer being de-TOASTed a couple of times
in quick succession, so a query-lifespan cache seems like the wrong
thing. Also, in most cases, repeated detoasting is probably quite
predictable: we could infer it from static analysis of the query. So
throwing ANY kind of cache at the problem seems like the wrong
approach unless the cache is super-cheap, which doesn't seem to be the
case with this proposal, because a cache caters to cases where we
can't know whether we're going to recompute the same result, and here,
that seems like something we could probably figure out.

Because I don't see any way to avoid regressions in the common case
where detoasting isn't repeated, I 

Reading timestamp values from Datums gives garbage values

2024-05-20 Thread Sushrut Shivaswamy
Hey,

I'm trying to read a timestamp column as EPOCH.
My query is as follows.
```
SELECT EXTRACT(EPOCH FROM timestamp_column) FROM table;

column
--

1716213097.86486
```
When running in the console this query gives valid epoch output which
appears to be of type double.

When trying to read the query response from the Datum, I get garbage values.
I've tried various types and none of them read the correct value.
```

Datum current_timestamp = SPI_getbinval(SPI_tuptable->vals[i],
SPI_tuptable->tupdesc, 5, );

double current_time = DatumGetFloat8(current_timestamp); // prints 0

int64 time = DatumGetUint64(current_timestamp); // prints 5293917674
```

Can you help me out with the correct way to read EPOCH values from datums?

Thanks,
Sushrut


Re: commitfest.postgresql.org is no longer fit for purpose

2024-05-20 Thread Robert Haas
On Mon, May 20, 2024 at 7:49 AM Alvaro Herrera  wrote:
> On 2024-May-19, Tom Lane wrote:
> > (The cfbot tends to discourage this, since as soon as one of the
> > patches is committed it no longer knows how to apply the rest.
> > Can we improve on that tooling somehow?)
>
> I think a necessary next step to further improve the cfbot is to get it
> integrated in pginfra.  Right now it runs somewhere in Thomas's servers
> or something, and there's no real integration with the commitfest proper
> except by scraping.

Yes, I think we really need to fix this. Also, there's a bunch of
mechanical work that could be done to make cfbot better, like making
the navigation not reset the scroll every time you drill down one
level through the build products.

I would also like to see the buildfarm and CI converged in some way.
I'm not sure how. I understand that the buildfarm tests more different
configurations than we can reasonably afford to do in CI, but there is
no sense in pretending that having two different systems doing similar
jobs has no cost.

-- 
Robert Haas
EDB: http://www.enterprisedb.com




Re: commitfest.postgresql.org is no longer fit for purpose

2024-05-20 Thread Robert Haas
On Sun, May 19, 2024 at 3:18 PM Tom Lane  wrote:
> Dmitry Dolgov <9erthali...@gmail.com> writes:
> > How do we make sure this time it will be different?
>
> Things *have* changed, if you take the long view.

That's true, but I think Dmitry's point is well-taken all the same: we
haven't really made a significant process improvement in many years,
and in some ways, I think things have been slowly degrading. I don't
believe it's necessary or possible to solve all of the accumulated
problems overnight, but we need to get serious about admitting that
there is a problem which, in my opinion, is an existential threat to
the project.

> IMV one really fundamental problem is the same as it's been for a
> couple of decades: too many patch submissions, too few committers.
> We can't fix that by just appointing a ton more committers, at least
> not if we want to keep the project's quality up.  We have to grow
> qualified committers.  IIRC, one of the main reasons for instituting
> the commitfests at all was the hope that if we got more people to
> spend time reading the code and reviewing patches, some of them would
> learn enough to become good committers.  I think that's worked, again
> taking a long view.  I just did some quick statistics on the commit
> history, and I see that we were hovering at somewhere around ten
> active committers from 1999 to 2012, but since then it's slowly crept
> up to about two dozen today.  (I'm counting "active" as "at least 10
> commits per year", which is an arbitrary cutoff --- feel free to slice
> the data for yourself.)  Meanwhile the number of submissions has also
> grown, so I'm not sure how much better the load ratio is.

That's an interesting statistic. I had not realized that the numbers
had actually grown significantly. However, I think that the
new-patch-submitter experience has not improved; if anything, I think
it may have gotten worse. It's hard to compare the subjective
experience between 2008 when I first got involved and now, especially
since at that time I was a rank newcomer experiencing things as a
newcomer, and now I'm a long-time committer trying to judge the
newcomer experience. But it seems to me that when I started, there was
more of a "middle tier" of people who were not committers but could do
meaningful review of patches and help you push them in the direction
of being something that a committer might not loathe. Now, I feel like
there are a lot of non-committer reviews that aren't actually adding a
lot of value: people come along and say the patch doesn't apply, or a
word is spelled wrong, and we don't get meaningful review of whether
the design makes sense, or if we do, it's wrong. Perhaps this is just
viewing the past with rose-colored glasses: I wasn't in as good a
position to judge the value of reviews that I gave and received at
that point as I am now. But what I do think is happening today is that
a lot of committer energy gets focused on the promising non-committers
who someone thinks might be able to become committers, and other
non-committers struggle to make any headway.

On the plus side, I think we make more of an effort not to be a jerk
to newcomers than we used to. I also have a strong hunch that it may
not be as good as it needs to be.

> * Patches that sit in the queue a long time tend to be ones that lack
> consensus, either about the goal or the details of how to achieve it.
> Sometimes "lacks consensus" really means "nobody but the author thinks
> this is a good idea, but we haven't mustered the will to say no".
> But I think it's more usually the case that there are plausible
> competing opinions about what the patch should do or how it should
> do it.  How can we resolve such differences and get something done?

This is a great question. We need to do better with that.

Also, it would be helpful to have better ways of handling it when the
author has gotten to a certain point with it but doesn't necessarily
have the time/skills/whatever to drive it forward. Such patches are
quite often a good idea, but it's not clear what we can do with them
procedurally other than hit the reject button, which doesn't feel
great.

> * Another reason for things sitting a long time is that they're too
> big to review without an unreasonable amount of effort.  We should
> encourage authors to break large patches into smaller stepwise
> refinements.  It may seem like that will result in taking forever
> to reach the end goal, but dropping a huge patchset on the community
> isn't going to give speedy results either.

Especially if it has a high rate of subtle defects, which is common.

> * Before starting this thread, Robert did a lot of very valuable
> review of some individual patches.  I think what prompted him to
> start the thread was the realization that he'd only made a small
> dent in the problem.  Maybe we could divide and conquer: get a
> dozen-or-so senior contributors to split up the list of pending
> patches and then look at each one with an 

Re: libpq compression (part 3)

2024-05-20 Thread Jacob Champion
On Fri, May 17, 2024 at 4:03 PM Jelte Fennema-Nio  wrote:
>
> On Fri, 17 May 2024 at 23:10, Jacob Champion
>  wrote:
> > We're talking about a transport-level option, though -- I thought the
> > proposal enabled compression before authentication completed? Or has
> > that changed?
>
> I think it would make sense to only compress messages after
> authentication has completed. The gain of compressing authentication
> related packets seems pretty limited.

Okay. But if we're relying on that for its security properties, it
needs to be enforced by the server.

> > (I'm suspicious of arguments that begin "well you can already do bad
> > things"
>
> Once logged in it's really easy to max out a core of the backend
> you're connected as. There's many trivial queries you can use to do
> that. An example would be:
> SELECT sum(i) from generate_series(1, 10) i;

This is just restating the "you can already do bad things" argument. I
understand that if your query gets executed, it's going to consume
resources on the thing that's executing it (for the record, though,
there are people working on constraining that). But introducing
disproportionate resource consumption into all traffic-inspecting
software, like pools and bouncers, seems like a different thing to me.
Many use cases are going to be fine with it, of course, but I don't
think it should be hand-waved.

--Jacob




Re: Underscore in positional parameters?

2024-05-20 Thread Erik Wienhold
On 2024-05-20 05:02 +0200, Tom Lane wrote:
> Erik Wienhold  writes:
> > On 2024-05-20 03:26 +0200, jian he wrote:
> >> /* Check parameter number is in range */
> >> if (paramno <= 0 || paramno > MaxAllocSize / sizeof(Oid))
> >> ereport(ERROR, ...
> 
> > Yes, it makes sense to show the upper bound.  How about a hint such as
> > "Valid parameters range from $%d to $%d."?
> 
> I kind of feel like this upper bound is ridiculous.  In what scenario
> is parameter 25000 not a mistake, if not indeed somebody trying
> to break the system?
> 
> The "Bind" protocol message only allows an int16 parameter count,
> so rejecting parameter numbers above 32K would make sense to me.

Agree.  I was already wondering upthread why someone would use that many
parameters.

Out of curiosity, I checked if there might be an even lower limit.  And
indeed, max_stack_depth puts a limit due to some recursive evaluation:

ERROR:  stack depth limit exceeded
HINT:  Increase the configuration parameter "max_stack_depth" (currently 
2048kB), after ensuring the platform's stack depth limit is adequate.

Attached is the stacktrace for EXECUTE on HEAD (I snipped most of the
recursive frames).

Running \bind, PREPARE, and EXECUTE with following number of parameters
works as expected, although the number varies between releases which is
not ideal IMO.  The commands hit the stack depth limit for #Params+1.

VersionCommand  #Params
-  ---  ---
HEAD (18cbed13d5)  \bind4365
HEAD (18cbed13d5)  PREPARE  8182
HEAD (18cbed13d5)  EXECUTE  4363
16.2   \bind3968
16.2   PREPARE  6889
16.2   EXECUTE  3966

Those are already pretty large numbers in my view (compared to the 100
parameters that we accept at most for functions).  And I guess nobody
complained about those limits yet, or they just increased
max_stack_depth.

The Python script to generate the test scripts:

import sys
n_params = 1 << 16
if len(sys.argv) > 1:
n_params = min(n_params, int(sys.argv[1]))
params = '+'.join(f'${i+1}::int' for i in range(n_params))
bind_vals = ' '.join('1' for _ in range(n_params))
exec_vals = ','.join('1' for _ in range(n_params))
print(fr"SELECT {params} \bind {bind_vals} \g")
print(f"PREPARE p AS SELECT {params};")
print(f"EXECUTE p ({exec_vals});")

-- 
Erik
Breakpoint 1, errfinish (filename=0x6441fddaec2e "postgres.c", lineno=3535, 
funcname=0x6441fdef87a0 <__func__.14> "check_stack_depth") at elog.c:479
479 ErrorData  *edata = [errordata_stack_depth];
#0  errfinish (filename=0x6441fddaec2e "postgres.c", lineno=3535, 
funcname=0x6441fdef87a0 <__func__.14> "check_stack_depth") at elog.c:479
#1  0x6441fd898173 in check_stack_depth () at postgres.c:3535
#2  0x6441fda5a9a2 in ExecInitExprRec (node=node@entry=0x6442373be5b0, 
state=state@entry=0x644236db7e90, resv=resv@entry=0x644236db7e98, 
resnull=resnull@entry=0x644236db7e95) at execExpr.c:899
#3  0x6441fda5dc12 in ExecInitExpr (node=node@entry=0x6442373be5b0, 
parent=parent@entry=0x0) at execExpr.c:153
#4  0x6441fdb52f58 in evaluate_expr (expr=0x6442373be5b0, 
result_type=result_type@entry=23, result_typmod=result_typmod@entry=-1, 
result_collation=result_collation@entry=0) at clauses.c:4987
#5  0x6441fdb53181 in evaluate_function (func_tuple=0x71b8821811c0, 
funcid=177, result_type=23, result_typmod=-1, result_collid=0, input_collid=0, 
args=0x6442373be520, funcvariadic=false, context=0x7ffd36b93cc0) at 
clauses.c:4503
#6  simplify_function (funcid=177, result_type=23, 
result_typmod=result_typmod@entry=-1, result_collid=0, input_collid=0, 
args_p=args_p@entry=0x7ffd36994940, funcvariadic=false, process_args=true, 
allow_non_const=true, context=0x7ffd36b93cc0) at clauses.c:4092
#7  0x6441fdb54624 in eval_const_expressions_mutator (node=, 
context=0x7ffd36b93cc0) at clauses.c:2639
#8  0x6441fdacdf3a in expression_tree_mutator_impl (node=0x644236d87398, 
mutator=mutator@entry=0x6441fdb53a10 , 
context=context@entry=0x7ffd36b93cc0) at nodeFuncs.c:3554
#9  0x6441fdb53781 in simplify_function (funcid=177, result_type=23, 
result_typmod=result_typmod@entry=-1, result_collid=0, input_collid=0, 
args_p=args_p@entry=0x7ffd36994b20, funcvariadic=false, process_args=true, 
allow_non_const=true, context=0x7ffd36b93cc0) at clauses.c:4083
#10 0x6441fdb54624 in eval_const_expressions_mutator (node=, 
context=0x7ffd36b93cc0) at clauses.c:2639
#11 0x6441fdacdf3a in expression_tree_mutator_impl (node=0x644236d87308, 
mutator=mutator@entry=0x6441fdb53a10 , 
context=context@entry=0x7ffd36b93cc0) at nodeFuncs.c:3554
#12 0x6441fdb53781 in simplify_function (funcid=177, result_type=23, 
result_typmod=result_typmod@entry=-1, result_collid=0, input_collid=0, 
args_p=args_p@entry=0x7ffd36994d00, funcvariadic=false, process_args=true, 
allow_non_const=true, context=0x7ffd36b93cc0) at clauses.c:4083
#13 0x6441fdb54624 in 

Re: Convert node test compile-time settings into run-time parameters

2024-05-20 Thread Tom Lane
Peter Eisentraut  writes:
> This patch converts the compile-time settings
>  COPY_PARSE_PLAN_TREES
>  WRITE_READ_PARSE_PLAN_TREES
>  RAW_EXPRESSION_COVERAGE_TEST

> into run-time parameters

>  debug_copy_parse_plan_trees
>  debug_write_read_parse_plan_trees
>  debug_raw_expression_coverage_test

I'm kind of down on this.  It seems like forcing a bunch of
useless-in-production debug support into the standard build.
What of this would be of any use to any non-developer?

regards, tom lane




Re: PostgreSQL 17 Beta 1 release announcement draft

2024-05-20 Thread Masahiko Sawada
On Mon, May 20, 2024 at 8:47 PM Jonathan S. Katz  wrote:
>
> On 5/20/24 2:58 AM, John Naylor wrote:
> > Hi Jon,
> >
> > Regarding vacuum "has shown up to a 6x improvement in overall time to
> > complete its work" -- I believe I've seen reported numbers close to
> > that only 1) when measuring the index phase in isolation or maybe 2)
> > the entire vacuum of unlogged tables with one, perfectly-correlated
> > index (testing has less variance with WAL out of the picture). I
> > believe tables with many indexes would show a lot of improvement, but
> > I'm not aware of testing that case specifically. Can you clarify where
> > 6x came from?
>
> Sawada-san showed me the original context, but I can't rapidly find it
> in the thread. Sawada-san, can you please share the numbers behind this?
>

I referenced the numbers that I measured during the development[1]
(test scripts are here[2]). IIRC I used unlogged tables and indexes,
and these numbers were the entire vacuum execution time including heap
scanning, index vacuuming and heap vacuuming.

FYI today I've run the same script with PG17 and measured the
execution times. Here are results:

monotonically ordered int column index:
system usage: CPU: user: 1.72 s, system: 0.47 s, elapsed: 2.20 s

uuid column index:
system usage: CPU: user: 3.62 s, system: 0.89 s, elapsed: 4.52 s

int & uuid indexes in parallel:
system usage: CPU: user: 2.24 s, system: 0.44 s, elapsed: 5.01 s

These numbers are better than ones I measured with v62 patch set as we
now introduced some optimization into tidstore (8a1b31e6 and f35bd9b).

Regards,

[1] 
https://www.postgresql.org/message-id/CAD21AoBci3Hujzijubomo1tdwH3XtQ9F89cTNQ4bsQijOmqnEw%40mail.gmail.com
[2] 
https://www.postgresql.org/message-id/CANWCAZYqWibTRCWs5mV57mLj1A0nbKX-eV5G%2Bd-KmBOGHTVY-w%40mail.gmail.com

-- 
Masahiko Sawada
Amazon Web Services: https://aws.amazon.com




Re: Speed up clean meson builds by ~25%

2024-05-20 Thread Robert Haas
On Sat, May 18, 2024 at 6:09 PM Andres Freund  wrote:
> A few tests with ccache disabled:

These tests seem to show no difference between the two releases, so I
wonder what you're intending to demonstrate here.

Locally, I have ninja 1.11.1. I'm sure Andres will be absolutely
shocked, shocked I say, to hear that I haven't upgraded to the very
latest.

Anyway, I tried a clean build with CC=clang without the patch and then
with the patch and got:

unpatched - real 1m9.872s
patched - real 1m6.130s

That's the time to run my script that first calls meson setup and then
afterward runs ninja. I tried ninja -v and put the output to a file.
With the patch:

[292/2402] /opt/local/bin/perl
../pgsql/src/interfaces/ecpg/preproc/parse.pl --srcdir
../pgsql/src/interfaces/ecpg/preproc --parser
../pgsql/src/interfaces/ecpg/preproc/../../../backend/parser/gram.y
--output src/interfaces/ecpg/preproc/preproc.y

And without:

[1854/2402] /opt/local/bin/perl
../pgsql/src/interfaces/ecpg/preproc/parse.pl --srcdir
../pgsql/src/interfaces/ecpg/preproc --parser
../pgsql/src/interfaces/ecpg/preproc/../../../backend/parser/gram.y
--output src/interfaces/ecpg/preproc/preproc.y

With my usual CC='ccache clang', I get real 0m37.500s unpatched and
real 0m37.786s patched. I also tried this with the original v1 patch
(not to be confused with the revised, still-v1 patch) and got real
37.950s.

So I guess I'm now feeling pretty unexcited about this. If the patch
really did what the subject line says, that would be nice to have.
However, since Tom will patch the underlying problem in v18, this will
only help people building the back-branches. Of those, it will only
help the people using a slow compiler; I read the thread as suggesting
that you need to be using clang rather than gcc and also not using
ccache. Plus, it sounds like you also need an old ninja version. Even
then, the highest reported savings is 10s and I only save 3s. I think
that's a small enough savings with enough conditionals that we should
not bother. It seems fine to say that people who need the fastest
possible builds of back-branches should use at least one of gcc,
ccache, and ninja >= 1.12.

I'll go mark this patch Rejected in the CommitFest. Incidentally, this
thread is an excellent object lesson in why it's so darn hard to cut
down the size of the CF. I mean, this is a 7-line patch and we've now
got a 30+ email thread about it. In my role as temporary
self-appointed wielder of the CommitFest mace, I have now spent
probably a good 2 hours trying to figure out what to do about it.
There are more than 230 active patches in the CommitFest. That means
CommitFest management would be more than a full-time job for an
experienced committer even if every patch were as simple as this one,
which is definitely not the case. If we want to restore some sanity
here, we're going to have to find some way of distributing the burden
across more people, including the patch authors. Note that Jelte's
last update to the thread is over a month ago. I'm not saying that
he's done something wrong, but I do strongly suspect that the time
that the community as whole has spent on this patch is a pretty
significant multiple of the time that he personally spent on it, and
such dynamics are bound to create scaling issues. I don't know how we
do better: I just want to highlight the problem.

-- 
Robert Haas
EDB: http://www.enterprisedb.com




Re: First draft of PG 17 release notes

2024-05-20 Thread Bruce Momjian
On Mon, May 20, 2024 at 01:23:02PM +0700, John Naylor wrote:
> Hi Bruce, thanks for doing this again!
> 
> I'm a bit late to this discussion -- there's been a bit of churn in
> the vacuum items, and some streams got crossed along the way. I've
> attached an attempt to rectify this.

Agreed, patch applied, thanks.

-- 
  Bruce Momjian  https://momjian.us
  EDB  https://enterprisedb.com

  Only you can decide what is important to you.




Re: PostgreSQL 17 Beta 1 release announcement draft

2024-05-20 Thread jian he
On Mon, May 20, 2024 at 5:35 AM Jonathan S. Katz  wrote:
>
> On 5/15/24 9:45 PM, Jonathan S. Katz wrote:
> > Hi,
> >
> > Attached is a copy of the PostgreSQL 17 Beta 1 release announcement
> > draft. This contains a user-facing summary of some of the features that
> > will be available in the Beta, as well as a call to test. I've made an
> > effort to group them logically around the different workflows they affect.
> >
> > A few notes:
> >
> > * The section with the features is not 80-char delimited. I will do that
> > before the final copy
> >
> > * There is an explicit callout that we've added in the SQL/JSON features
> > that were previously reverted in PG15. I want to ensure we're
> > transparent about that, but also use it as a hook to get people testing.
> >
> > When reviewing:
> >
> > * Please check for correctness of feature descriptions, keeping in mind
> > this is targeted for a general audience
> >
> > * Please indicate if you believe there's a notable omission, or if we
> > should omit any of these callouts
> >
> > * Please indicate if a description is confusing - I'm happy to rewrite
> > to ensure it's clearer.
> >
> > Please provide feedback no later than Wed 2024-05-22 18:00 UTC. As the
> > beta release takes some extra effort, I want to ensure all changes are
> > in with time to spare before release day.
>
> Thanks for all the feedback to date. Please see the next revision.
> Again, please provide feedback no later than 2024-05-22 18:00 UTC.
>
> Thanks,
>
> Jonathan
>

release note (https://momjian.us/pgsql_docs/release-17.html)
is
"Add jsonpath methods to convert JSON values to other JSON data types
(Jeevan Chalke)"


>> Additionally, PostgreSQL 17 adds more functionality to its `jsonpath` 
>> implementation, including the ability to convert JSON values to different 
>> data types.
so, I am not sure this is 100% correct.

Maybe we can rephrase it like:

>> Additionally, PostgreSQL 17 adds more functionality to its `jsonpath` 
>> implementation, including the ability to convert JSON values to other JSON 
>> data types.




Re: generic plans and "initial" pruning

2024-05-20 Thread Amit Langote
On Sun, May 19, 2024 at 9:39 AM David Rowley  wrote:
> For #1, the locks taken for SELECT queries are less likely to conflict
> with other locks obtained by PostgreSQL, but at least at the moment if
> someone is getting deadlocks with a DDL type operation, they can
> change their query or DDL script so that locks are taken in the same
> order.  If we allowed executor startup to do this then if someone
> comes complaining that PG18 deadlocks when PG17 didn't we'd just have
> to tell them to live with it.  There's a comment at the bottom of
> find_inheritance_children_extended() just above the qsort() which
> explains about the deadlocking issue.

Thought to chime in on this.

A deadlock may occur with the execution-time locking proposed in the
patch if the DDL script makes assumptions about how a cached plan's
execution determines the locking order for children of multiple parent
relations. Specifically, the deadlock can happen if the script tries
to lock the child relations directly, instead of locking them through
their respective parent relations.  The patch doesn't change the order
of locking of relations mentioned in the query, because that's defined
in AcquirePlannerLocks().

--
Thanks, Amit Langote




Re: Injection points: preloading and runtime arguments

2024-05-20 Thread Andrey M. Borodin


> On 20 May 2024, at 17:01, Andrey M. Borodin  wrote:

Ugh, accidentally send without attaching the patch itself. Sorry for the noise.


Best regards, Andrey Borodin.


0001-Add-multixact-CV-sleep.patch
Description: Binary data




Re: Injection points: preloading and runtime arguments

2024-05-20 Thread Andrey M. Borodin
Hi!

> On 20 May 2024, at 08:18, Michael Paquier  wrote:

Both features look useful to me.
I've tried to rebase my test of CV sleep during multixact generation[0]. I used 
it like this:

INJECTION_POINT_PRELOAD("GetNewMultiXactId-done");
multi = GetNewMultiXactId(nmembers, ); // starts critsection
INJECTION_POINT("GetNewMultiXactId-done");

And it fails like this:

2024-05-20 16:50:40.430 +05 [21830] 001_multixact.pl LOG:  statement: select 
test_create_multixact();
TRAP: failed Assert("CritSectionCount == 0 || (context)->allowInCritSection"), 
File: "mcxt.c", Line: 1185, PID: 21830
0   postgres0x000101452ed0 ExceptionalCondition 
+ 220
1   postgres0x0001014a6050 MemoryContextAlloc + 
208
2   postgres0x0001011c3bf0 
dsm_create_descriptor + 72
3   postgres0x0001011c3ef4 dsm_attach + 400
4   postgres0x0001014990d8 dsa_attach + 24
5   postgres0x0001011c716c init_dsm_registry + 
240
6   postgres0x0001011c6e60 GetNamedDSMSegment + 
456
7   injection_points.dylib  0x000101c871f8 injection_init_shmem 
+ 60
8   injection_points.dylib  0x000101c86f1c injection_wait + 64
9   postgres0x00010148e228 
InjectionPointRunInternal + 376
10  postgres0x00010148e0a4 InjectionPointRun + 
32
11  postgres0x000100cab798 
MultiXactIdCreateFromMembers + 344
12  postgres0x000100cab604 MultiXactIdCreate + 
312

Am I doing something wrong? Seems like extension have to know too that it is 
preloaded.


Best regards, Andrey Borodin.

[0] 
https://www.postgresql.org/message-id/0925F9A9-4D53-4B27-A87E-3D83A757B0E0%40yandex-team.ru



Re: remaining sql/json patches

2024-05-20 Thread Amit Langote
Hi Thom,

On Thu, May 16, 2024 at 8:50 AM Thom Brown  wrote:
> On Mon, 8 Apr 2024 at 10:09, Amit Langote  wrote:
>>
>> On Mon, Apr 8, 2024 at 2:02 PM jian he  wrote:
>> > On Mon, Apr 8, 2024 at 11:21 AM jian he  
>> > wrote:
>> > >
>> > > On Mon, Apr 8, 2024 at 12:34 AM jian he  
>> > > wrote:
>> > > >
>> > > > On Sun, Apr 7, 2024 at 9:36 PM Amit Langote  
>> > > > wrote:
>> > > > > 0002 needs an expanded commit message but I've run out of energy 
>> > > > > today.
>> > > > >
>> > >
>> > > other than that, it looks good to me.
>> >
>> > one more tiny issue.
>> > +EXPLAIN (COSTS OFF, VERBOSE) SELECT * FROM jsonb_table_view1;
>> > +ERROR:  relation "jsonb_table_view1" does not exist
>> > +LINE 1: EXPLAIN (COSTS OFF, VERBOSE) SELECT * FROM jsonb_table_view1...
>> > +   ^
>> > maybe you want
>> > EXPLAIN (COSTS OFF, VERBOSE) SELECT * FROM jsonb_table_view7;
>> > at the end of the sqljson_jsontable.sql.
>> > I guess it will be fine, but the format json explain's out is quite big.
>> >
>> > you also need to `drop table s cascade;` at the end of the test?
>>
>> Pushed after fixing this and other issues.  Thanks a lot for your
>> careful reviews.
>>
>> I've marked the CF entry for this as committed now:
>> https://commitfest.postgresql.org/47/4377/
>>
>> Let's work on the remaining PLAN clause with a new entry in the next
>> CF, possibly in a new email thread.
>
>
> I've just taken a look at the doc changes,

Thanks for taking a look.

> and I think we need to either remove the leading "select" keyword, or 
> uppercase it in the examples.
>
> For example (on 
> https://www.postgresql.org/docs/devel/functions-json.html#SQLJSON-QUERY-FUNCTIONS):
>
> json_exists ( context_item, path_expression [ PASSING { value AS varname } [, 
> ...]] [ { TRUE | FALSE | UNKNOWN | ERROR } ON ERROR ])
>
> Returns true if the SQL/JSON path_expression applied to the context_item 
> using the PASSING values yields any items.
> The ON ERROR clause specifies the behavior if an error occurs; the default is 
> to return the boolean FALSE value. Note that if the path_expression is strict 
> and ON ERROR behavior is ERROR, an error is generated if it yields no items.
> Examples:
> select json_exists(jsonb '{"key1": [1,2,3]}', 'strict $.key1[*] ? (@ > 2)') → 
> t
> select json_exists(jsonb '{"a": [1,2,3]}', 'lax $.a[5]' ERROR ON ERROR) → f
> select json_exists(jsonb '{"a": [1,2,3]}', 'strict $.a[5]' ERROR ON ERROR) →
> ERROR:  jsonpath array subscript is out of bounds
>
> Examples are more difficult to read when keywords appear to be at the same 
> level as predicates.  Plus other examples within tables on the same page 
> don't start with "select", and further down, block examples uppercase 
> keywords.  Either way, I don't like it as it is.

I agree that the leading SELECT should be removed from these examples.
Also, the function names should be capitalized both in the syntax
description and in the examples, even though other functions appearing
on this page aren't.

> Separate from this, I think these tables don't scan well (see json_query for 
> an example of what I'm referring to).  There is no clear separation of the 
> syntax definition, the description, and the example. This is more a matter 
> for the website mailing list, but I'm expressing it here to check whether 
> others agree.

Hmm, yes, I think I forgot to put  around the syntax like
it's done for a few other functions listed on the page.

How about the attached?  Other than the above points, it removes the
 tags from the description text of each function to turn it into
a single paragraph, because the multi-paragraph style only seems to
appear in this table and it's looking a bit weird now.  Though it's
also true that the functions in this table have the longest
descriptions.

-- 
Thanks, Amit Langote


v1-0001-Doc-some-stylistic-fixes-to-SQL-JSON-query-functi.patch
Description: Binary data


Re: commitfest.postgresql.org is no longer fit for purpose

2024-05-20 Thread Alvaro Herrera
On 2024-May-19, Tom Lane wrote:

> (The cfbot tends to discourage this, since as soon as one of the
> patches is committed it no longer knows how to apply the rest.
> Can we improve on that tooling somehow?)

I think a necessary next step to further improve the cfbot is to get it
integrated in pginfra.  Right now it runs somewhere in Thomas's servers
or something, and there's no real integration with the commitfest proper
except by scraping.

-- 
Álvaro Herrera   48°01'N 7°57'E  —  https://www.EnterpriseDB.com/
"La libertad es como el dinero; el que no la sabe emplear la pierde" (Alvarez)




Re: PostgreSQL 17 Beta 1 release announcement draft

2024-05-20 Thread Jonathan S. Katz

On 5/20/24 2:58 AM, John Naylor wrote:

Hi Jon,

Regarding vacuum "has shown up to a 6x improvement in overall time to
complete its work" -- I believe I've seen reported numbers close to
that only 1) when measuring the index phase in isolation or maybe 2)
the entire vacuum of unlogged tables with one, perfectly-correlated
index (testing has less variance with WAL out of the picture). I
believe tables with many indexes would show a lot of improvement, but
I'm not aware of testing that case specifically. Can you clarify where
6x came from?


Sawada-san showed me the original context, but I can't rapidly find it 
in the thread. Sawada-san, can you please share the numbers behind this?


We can adjust the claim - but I'd like to ensure we highlight how the 
changes to vacuum will visibly impact users.


Jonathan


OpenPGP_signature.asc
Description: OpenPGP digital signature


Re: PostgreSQL 17 Beta 1 release announcement draft

2024-05-20 Thread Jonathan S. Katz

On 5/19/24 7:24 PM, David Rowley wrote:

On Mon, 20 May 2024 at 09:35, Jonathan S. Katz  wrote:

Thanks for all the feedback to date. Please see the next revision.
Again, please provide feedback no later than 2024-05-22 18:00 UTC.


Thanks for the updates.


[`COPY`](https://www.postgresql.org/docs/17/sql-copy.html) is used to 
efficiently bulk load data into PostgreSQL, and with PostgreSQL 17 shows a 2x 
performance improvement when loading large rows.


The 2x thing mentioned by Jelte is for COPY TO rather than COPY FROM.
So I think "exporting" or "sending large rows to the client"  rather
than "loading".


Thanks for the clarification - I've edited it as such. That also brings 
up a good point to highlight that COPY is not just for loading (since my 
bias is to do loads these days :) Now it reads:


[`COPY`](https://www.postgresql.org/docs/17/sql-copy.html) is used to 
efficiently bulk load and export data from PostgreSQL, and now with 
PostgreSQL 17 you may see up to a 2x performance improvement when 
exporting large rows.



There's also a stray "with" in that sentence.


Thanks, fixed.

Jonathan



OpenPGP_signature.asc
Description: OpenPGP digital signature


Re: Convert node test compile-time settings into run-time parameters

2024-05-20 Thread Ranier Vilela
Em seg., 20 de mai. de 2024 às 04:28, Peter Eisentraut 
escreveu:

> This patch converts the compile-time settings
>
>  COPY_PARSE_PLAN_TREES
>  WRITE_READ_PARSE_PLAN_TREES
>  RAW_EXPRESSION_COVERAGE_TEST
>
> into run-time parameters
>
>  debug_copy_parse_plan_trees
>  debug_write_read_parse_plan_trees
>  debug_raw_expression_coverage_test
>
> They can be activated for tests using PG_TEST_INITDB_EXTRA_OPTS.
>
> The effect is the same, but now you don't need to recompile in order to
> use these checks.
>
> The compile-time symbols are kept for build farm compatibility, but they
> now just determine the default value of the run-time settings.
>
> Possible concerns:
>
> - Performance?  Looking for example at pg_parse_query() and its
> siblings, they also check for other debugging settings like
> log_parser_stats in the main code path, so it doesn't seem to be a concern.
>
> - Access control?  I have these settings as PGC_USERSET for now. Maybe
> they should be PGC_SUSET?
>
> Another thought:  Do we really need three separate settings?
>
What is the use for production use?

best regards,
Ranier Vilela


Re: PostgreSQL 17 Beta 1 release announcement draft

2024-05-20 Thread David Rowley
On Mon, 20 May 2024 at 23:16, Thom Brown  wrote:
>
> On Mon, 20 May 2024 at 00:24, David Rowley  wrote:
>>
>> On Mon, 20 May 2024 at 09:35, Jonathan S. Katz  wrote:
>> > Thanks for all the feedback to date. Please see the next revision.
>> > Again, please provide feedback no later than 2024-05-22 18:00 UTC.
>>
>> Thanks for the updates.
>>
>> > [`COPY`](https://www.postgresql.org/docs/17/sql-copy.html) is used to 
>> > efficiently bulk load data into PostgreSQL, and with PostgreSQL 17 shows a 
>> > 2x performance improvement when loading large rows.
>>
>> The 2x thing mentioned by Jelte is for COPY TO rather than COPY FROM.
>> So I think "exporting" or "sending large rows to the client"  rather
>> than "loading".
>>
>> There's also a stray "with" in that sentence.
>
>
> Are you referring to the "with" in "and with PostgreSQL 17"? If so, it looks 
> valid to me.

Yes that one.  It sounds wrong to me, but that's from a British
English point of view. I'm continuing to learn the subtle differences
with American English. Maybe this is one.

It would make sense to me if it was "and with PostgreSQL 17, a 2x
...". From my point of view either "with" shouldn't be there or
"shows" could be replaced with a comma. However, if you're ok with it,
I'll say no more. I know this is well into your territory.

David




Re: PostgreSQL 17 Beta 1 release announcement draft

2024-05-20 Thread Thom Brown
On Mon, 20 May 2024 at 00:24, David Rowley  wrote:

> On Mon, 20 May 2024 at 09:35, Jonathan S. Katz 
> wrote:
> > Thanks for all the feedback to date. Please see the next revision.
> > Again, please provide feedback no later than 2024-05-22 18:00 UTC.
>
> Thanks for the updates.
>
> > [`COPY`](https://www.postgresql.org/docs/17/sql-copy.html) is used to
> efficiently bulk load data into PostgreSQL, and with PostgreSQL 17 shows a
> 2x performance improvement when loading large rows.
>
> The 2x thing mentioned by Jelte is for COPY TO rather than COPY FROM.
> So I think "exporting" or "sending large rows to the client"  rather
> than "loading".
>
> There's also a stray "with" in that sentence.
>

Are you referring to the "with" in "and with PostgreSQL 17"? If so, it
looks valid to me.
-- 
Thom


Re: Fix src/test/subscription/t/029_on_error.pl test when wal_debug is enabled

2024-05-20 Thread Amit Kapila
On Fri, May 17, 2024 at 5:25 AM Michael Paquier  wrote:
>
> On Thu, May 16, 2024 at 09:00:47AM +0530, Amit Kapila wrote:
> > This can only be a problem if the apply worker generates more LOG
> > entries with the required context but it won't do that unless there is
> > an operation on the publisher to replicate. If we see any such danger
> > then I agree this can break on some slow machines but as of now, I
> > don't see any such race condition.
>
> Perhaps, still I'm not completely sure if this assumption is going to
> always stand for all the possible configurations we support.
>

As per my understanding, this will primarily rely on the apply worker
design, not the other configurations, whether we see additional LOG.

>  So,
> rather than coming back to this test again, I would choose to make the
> test as stable as possible from the start.  That's what mapping with
> the error message would offer when grabbing the LSN from the CONTEXT
> part of it, because there's a one-one mapping between the expected
> ERROR and its CONTEXT from which the information used by the test is
> retrieved.
>

I was slightly hesitant to do an ERROR string-based check because the
error string can change and it doesn't seem to bring additional
stability for this particular test. But if you and others are still
not convinced with the simple fix suggested by me then feel free to
proceed with an error-string based check.

-- 
With Regards,
Amit Kapila.




Re: speed up a logical replica setup

2024-05-20 Thread Shlok Kyal
Hi,
>
> I was trying to test this utility when 'sync_replication_slots' is on
> and it gets in an ERROR loop [1] and never finishes. Please find the
> postgresql.auto used on the standby attached. I think if the standby
> has enabled sync_slots, you need to pass dbname in
> GenerateRecoveryConfig(). I couldn't test it further but I wonder if
> there are already synced slots on the standby (either due to
> 'sync_replication_slots' or users have used
> pg_sync_replication_slots() before invoking pg_createsubscriber),
> those would be retained as it is on new subscriber and lead to
> unnecessary WAL retention and dead rows.
>
> [1]
> 2024-04-30 11:50:43.239 IST [12536] LOG:  slot sync worker started
> 2024-04-30 11:50:43.247 IST [12536] ERROR:  slot synchronization
> requires dbname to be specified in primary_conninfo

Hi,

I tested the scenario posted by Amit in [1], in which retaining synced
slots lead to unnecessary WAL retention and ERROR. This is raised as
the second open point in [2].
The steps to reproduce the issue:
(1) Setup physical replication with sync slot feature turned on by
setting sync_replication_slots = 'true' or using
pg_sync_replication_slots() on the standby node.
For physical replication setup, run pg_basebackup with -R  and -d option.
(2) Create a logical replication slot on primary node with failover
option as true. A corresponding slot is created on standby as part of
sync slot feature.
(3) Run pg_createsubscriber on standby node.
(4) On Checking for the replication slot on standby node, I noticed
that the logical slots created in step 2 are retained.
 I have attached the script to reproduce the issue.

I and Kuroda-san worked to resolve open points. Here are patches to
solve the second and third point in [2].
Patches proposed by Euler are also attached just in case, but they
were not modified.

v2-0001: not changed
v2-0002: not changed
v2-0003: ensures the slot sync is disabled during the conversion. This
resolves the second point.
v2-0004: drops sync slots which may be retained after running. This
resolves the second point.
v2-0005: removes misleading output messages in dry-run. This resolves
the third point.

[1]: 
https://www.postgresql.org/message-id/CAA4eK1KdCb%2B5sjYu6qCMXXdCX1y_ihr8kFzMozq0%3DP%3DauYxgog%40mail.gmail.com
[2]: 
https://www.postgresql.org/message-id/CAA4eK1J22UEfrqx222h5j9DQ7nxGrTbAa_BC%2B%3DmQXdXs-RCsew%40mail.gmail.com

Thanks and Regards,
Shlok Kyal
# cleanup
rm -rf ../primary ../standby primary.log standby.log

# setup primary node
./initdb -D ../primary
 
cat << EOF >> ../primary/postgresql.conf
wal_level = logical
EOF

./pg_ctl -D ../primary -l primary.log start
./psql -d postgres -c "CREATE table t1 (c1 int);"
./psql -d postgres -c "Insert into t1 values(1);"
./psql -d postgres -c "Insert into t1 values(2);"
./psql -d postgres -c "INSERT into t1 values(3);"
./psql -d postgres -c "INSERT into t1 values(4);"

# setup standby node with sync slot feature
./pg_basebackup -h localhost -X stream -v -W -R -S 'sb1' -C -D ../standby/ -d 'dbname=postgres' 

cat << EOF >> ../standby/postgresql.conf
sync_replication_slots = 'true'
hot_standby_feedback = 'on'
port = 9000
EOF

./pg_ctl -D ../standby -l standby.log start

# create a replication slot on primary with failover option
./psql -d postgres -c "SELECT 'init' FROM pg_create_logical_replication_slot('failover_true_slot_2', 'test_decoding', false, false, true);"
sleep 2

# check if slots are synced on standby
./psql -d postgres -p 9000 -c "select * from pg_replication_slots;" 
./pg_ctl -D ../standby -l standby.log stop

# run pg_createsubscriber on standby
./pg_createsubscriber -D ../standby/ -p 9000 -P "host=localhost port=5432 dbname=postgres" -d postgres -v

# check if replication slots are retained after running pg_createsubscriber
./pg_ctl -D ../standby -l standby.log start
./psql -d postgres -p 9000 -c "select * from pg_replication_slots;" 

./pg_ctl -D ../standby -l standby.log stop
./pg_ctl -D ../primary -l primary.log stop


v2-0001-Improve-the-code-that-checks-if-the-recovery-is-f.patch
Description: Binary data


v2-0002-Improve-the-code-that-checks-if-the-primary-slot-.patch
Description: Binary data


v2-0003-Disable-slot-sync-during-the-convertion.patch
Description: Binary data


v2-0004-Drop-replication-slots-which-had-been-synchronize.patch
Description: Binary data


v2-0005-Avoid-outputing-some-messages-in-dry_run-mode.patch
Description: Binary data


Re: Doc limitation update proposal: include out-of-line OID usage per TOAST-ed columns

2024-05-20 Thread Jakub Wartak
On Tue, May 14, 2024 at 8:19 PM Robert Haas  wrote:
>
> I looked at your version and wrote something that is shorter and
> doesn't touch any existing text. Here it is.

Hi Robert, you are a real tactician here - thanks for whatever
references the original problem! :) Maybe just slight hint nearby
expensive (to me indicating a just a CPU problem?):

finding an OID that is still free can become expensive ->
finding an OID that is still free can become expensive, thus
significantly increasing INSERT/UPDATE response time.

? (this potentially makes it easier in future to pinpoint the user's
problem to the this exact limitation; but feel free to ignore that too
as I'm not attached to any of those versions)

-J.




Re: PostgreSQL 17 Beta 1 release announcement draft

2024-05-20 Thread David Rowley
On Mon, 20 May 2024 at 22:11, Alvaro Herrera  wrote:
>
> On 2024-May-16, David Rowley wrote:
>
> > On Thu, 16 May 2024 at 17:37, zaidagilist  wrote:
> > > I am trying to open the 17 docs but it looks removed. Getting
> > > following message "Page not found"
> > >
> > > https://www.postgresql.org/docs/17/
> >
> > It's called "devel" for "development" until we branch sometime before July:
> >
> > https://www.postgresql.org/docs/devel/
>
> Hmm, but that would mean that the Beta1 announce would ship full of
> links that will remain broken until July.  I'm not sure what the
> workflow for this is, but I hope the /17/ URLs would become valid with
> beta1, later this week.

I didn't quite click that it was Jonathan's links that were being
complained about.

I don't know how the website picks up where to link the doc page for a
given version.  I see from e0b82fc8e8 that the PACKAGE_VERSION was
changed from 16devel to 16beta1. Does the website have something that
extracts "devel" from the former and "16" from the latter?  I see the
release announcement for 16beta1 had /16/ links per [1].  So, I guess
it works. I just don't know how.

David

[1] https://www.postgresql.org/about/news/postgresql-16-beta-1-released-2643/




Re: speed up a logical replica setup

2024-05-20 Thread Amit Kapila
On Sun, May 19, 2024 at 4:25 AM Thomas Munro  wrote:
>
> 040_pg_createsubscriber.pl seems to be failing occasionally on
> culicidae near "--dry-run on node S".  I couldn't immediately see why.
> That animal is using EXEC_BACKEND and I also saw a one-off failure a
> bit like that on my own local Linux + EXEC_BACKEND test run
> (sorry I didn't keep the details around).  Coincidence?
>

AFAICS, this is the same as one of the two BF failures being discussed
in this thread.

-- 
With Regards,
Amit Kapila.




Re: PostgreSQL 17 Beta 1 release announcement draft

2024-05-20 Thread Alvaro Herrera
On 2024-May-16, David Rowley wrote:

> On Thu, 16 May 2024 at 17:37, zaidagilist  wrote:
> > I am trying to open the 17 docs but it looks removed. Getting
> > following message "Page not found"
> >
> > https://www.postgresql.org/docs/17/
> 
> It's called "devel" for "development" until we branch sometime before July:
> 
> https://www.postgresql.org/docs/devel/

Hmm, but that would mean that the Beta1 announce would ship full of
links that will remain broken until July.  I'm not sure what the
workflow for this is, but I hope the /17/ URLs would become valid with
beta1, later this week.

-- 
Álvaro Herrera PostgreSQL Developer  —  https://www.EnterpriseDB.com/
"No renuncies a nada. No te aferres a nada."




Re: PostgreSQL 17 Beta 1 release announcement draft

2024-05-20 Thread Alvaro Herrera
On 2024-May-19, Jonathan S. Katz wrote:

> ### Query and Operational Performance Improvements

In this section I'd add mention the new GUCs to control SLRU memory
size, which is going to be a huge performance boon for cases where the
current fixed-size buffers cause bottlenecks.  Perhaps something like

"Increase scalability of transaction, subtransaction and multixact
shared memory buffer handling, and make their buffer sizes configurable".

I don't know if we have any published numbers of the performance
improvement achieved, but with this patch (or ancestor ones) some
systems go from completely unoperational to working perfectly fine.
Maybe the best link is here
https://www.postgresql.org/docs/devel/runtime-config-resource.html#GUC-MULTIXACT-MEMBER-BUFFERS
though exactly which GUC affects any particular user is workload-
dependant, so I'm not sure how best to do it.

> ### Developer Experience

I think this section should also include the libpq query cancellation
improvements Jelte wrote.  Maybe something like "On the client side,
PostgreSQL 17 provides better support for asynchronous and more secure
query cancellation routines in libpq."  --> link to
https://www.postgresql.org/docs/17/libpq-cancel.html

-- 
Álvaro Herrera PostgreSQL Developer  —  https://www.EnterpriseDB.com/
"At least to kernel hackers, who really are human, despite occasional
rumors to the contrary" (LWN.net)




Re: using extended statistics to improve join estimates

2024-05-20 Thread Andrei Lepikhov

On 20/5/2024 15:52, Andy Fan wrote:


Hi Andrei,


On 4/3/24 01:22, Tomas Vondra wrote:

Cool! There's obviously no chance to get this into v18, and I have stuff
to do in this CF. But I'll take a look after that.

I'm looking at your patch now - an excellent start to an eagerly awaited
feature!
A couple of questions:
1. I didn't find the implementation of strategy 'c' - estimation by the
number of distinct values. Do you forget it?


What do you mean the "strategy 'c'"?

As described in 0001-* patch:
* c) No extended stats with MCV. If there are multiple join clauses,
* we can try using ndistinct coefficients and do what eqjoinsel does.




2. Can we add a clauselist selectivity hook into the core (something
similar the code in attachment)? It can allow the development and
testing of multicolumn join estimations without patching the core.


The idea LGTM. But do you want

+   if (clauselist_selectivity_hook)
+   s1 = clauselist_selectivity_hook(root, clauses, varRelid, 
jointype,
+

rather than

+   if (clauselist_selectivity_hook)
+   *return* clauselist_selectivity_hook(root, clauses, ..)
Of course - library may estimate not all the clauses - it is a reason, 
why I added input/output parameter 'estimatedclauses' by analogy with 
statext_clauselist_selectivity.


--
regards,
Andrei Lepikhov
Postgres Professional





Re: PostgreSQL 17 Beta 1 release announcement draft

2024-05-20 Thread Bertrand Drouvot
Hi,

On Sun, May 19, 2024 at 05:10:10PM -0400, Jonathan S. Katz wrote:
> On 5/16/24 1:15 AM, Bertrand Drouvot wrote:
> > Hi,
> > 
> > On Wed, May 15, 2024 at 09:45:35PM -0400, Jonathan S. Katz wrote:
> > > Hi,
> > > 
> > > Attached is a copy of the PostgreSQL 17 Beta 1 release announcement draft.
> > 
> > Thanks for working on it!
> > 
> > I've one comment:
> > 
> > > PostgreSQL 17 also introduces a new view, 
> > > [`pg_wait_events`](https://www.postgresql.org/docs/17/view-pg-wait-events.html),
> > >  which provides descriptions about wait events and can be combined with 
> > > `pg_stat_activity` to give more insight into an operation.
> > 
> > Instead of "to give more insight into an operation", what about "to give 
> > more
> > insight about what a session is waiting for (should it be active)"?
> 
> I put:
> 
> "to give more in insight into why a session is blocked."

Thanks!

> 
> Does that work?
> 

I think using "waiting" is better (as the view is "pg_wait_events" and the
join with pg_stat_activity would be on the "wait_event_type" and "wait_event"
columns).

The reason I mentioned "should it be active" is because wait_event and 
wait_event_type
could be non empty in pg_stat_activity while the session is not in an active 
state
anymore (then not waiting).

A right query would be like the one in [1]:

"
SELECT a.pid, a.wait_event, w.description
  FROM pg_stat_activity a JOIN
   pg_wait_events w ON (a.wait_event_type = w.type AND
a.wait_event = w.name)
  WHERE a.wait_event is NOT NULL and a.state = 'active';
"

means filtering on the "active" state too, and that's what the description
proposal I made was trying to highlight.

[1]: https://www.postgresql.org/docs/devel/monitoring-stats.html

Regards,

-- 
Bertrand Drouvot
PostgreSQL Contributors Team
RDS Open Source Databases
Amazon Web Services: https://aws.amazon.com




Re: commitfest.postgresql.org is no longer fit for purpose

2024-05-20 Thread Mark Cave-Ayland

On 20/05/2024 06:56, Mark Cave-Ayland wrote:

In general you find that a series consists of 2 parts: 1) a set of refactorings to 
enable a new feature and 2) the new feature itself. Even if the details of 2) are 
still under discussion, often it is possible to merge 1) fairly quickly which also 
has the knock-on effect of reducing the size of later iterations of the series. This 
also helps with new contributors since having parts of the series merged sooner helps 
them feel valued and helps to provide immediate feedback.


[resend due to DKIM header failure]

Something else I also notice is that PostgreSQL doesn't have a MAINTAINERS or 
equivalent file, so when submitting patches it's difficult to know who is expected to 
review and/or commit changes to a particular part of the codebase (this is true both 
with and without the CF system).



ATB,

Mark.




Re: Postgres and --config-file option

2024-05-20 Thread Aleksander Alekseev
Hi,

> Robert Haas  writes:
> > If the reason that somebody is upset is because it's not technically
> > true to say that you *must* do one of those things, we could fix that
> > with "You must" -> "You can" or with "You must specify" -> "Specify".
> > The patch you propose is also not terrible or anything, but it goes in
> > the direction of listing every alternative, which will become
> > unpalatable as soon as somebody adds one more way to do it, or maybe
> > it's unpalatable already.
>
> I agree that it's not necessary or particularly useful for this hint
> to be exhaustive.  I could get behind your suggestion of
> s/You must specify/Specify/, but I also think it's fine to do nothing.

Fair enough, let's leave the help message as is then. I closed the
corresponding CF entry.

-- 
Best regards,
Aleksander Alekseev




Re: commitfest.postgresql.org is no longer fit for purpose

2024-05-20 Thread Mark Cave-Ayland

On 20/05/2024 02:09, Tom Lane wrote:


Bruce Momjian  writes:

On Sun, May 19, 2024 at 03:18:11PM -0400, Tom Lane wrote:

* Another reason for things sitting a long time is that they're too
big to review without an unreasonable amount of effort.  We should
encourage authors to break large patches into smaller stepwise
refinements.  It may seem like that will result in taking forever
to reach the end goal, but dropping a huge patchset on the community
isn't going to give speedy results either.



I think it is sometimes hard to incrementally apply patches if the
long-term goal isn't agreed or know to be achievable.


True.  The value of the earlier patches in the series can be unclear
if you don't understand what the end goal is.  But I think people
could post a "road map" of how they intend a patch series to go.

Another way of looking at this is that sometimes people do post large
chunks of work in long many-patch sets, but we tend to look at the
whole series as something to review and commit as one (or I do, at
least).  We should be more willing to bite off and push the earlier
patches in such a series even when the later ones aren't entirely
done.


[resend due to DKIM header failure]

Right. As an observation from someone who used to dabble in PostgreSQL internals a 
number of years ago (and who now spends a lot of time working on other well-known 
projects), this is something that really stands out with the current PostgreSQL workflow.


In general you find that a series consists of 2 parts: 1) a set of refactorings to 
enable a new feature and 2) the new feature itself. Even if the details of 2) are 
still under discussion, often it is possible to merge 1) fairly quickly which also 
has the knock-on effect of reducing the size of later iterations of the series. This 
also helps with new contributors since having parts of the series merged sooner helps 
them feel valued and helps to provide immediate feedback.


The other issue I mentioned last time this discussion arose is that I really miss the 
standard email-based git workflow for PostgreSQL: writing a versioned cover letter 
helps reviewers as the summary provides a list of changes since the last iteration, 
and having separate emails with a PATCH prefix allows patches to be located quickly.


Finally as a reviewer I find that having contributors use git format-patch and 
send-email makes it easier for me to contribute, since I can simply hit "Reply" and 
add in-line comments for the parts of the patch I feel I can review. At the moment I 
have to locate the emails that contain patches and save the attachments before I can 
even get to starting the review process, making the initial review barrier that 
little bit higher.



ATB,

Mark.




Re: Pgoutput not capturing the generated columns

2024-05-20 Thread vignesh C
On Mon, 20 May 2024 at 13:49, Masahiko Sawada  wrote:
>
> Hi,
>
> On Wed, May 8, 2024 at 4:14 PM Shubham Khanna
>  wrote:
> >
> > On Wed, May 8, 2024 at 11:39 AM Rajendra Kumar Dangwal
> >  wrote:
> > >
> > > Hi PG Hackers.
> > >
> > > We are interested in enhancing the functionality of the pgoutput plugin 
> > > by adding support for generated columns.
> > > Could you please guide us on the necessary steps to achieve this? 
> > > Additionally, do you have a platform for tracking such feature requests? 
> > > Any insights or assistance you can provide on this matter would be 
> > > greatly appreciated.
> >
> > The attached patch has the changes to support capturing generated
> > column data using ‘pgoutput’ and’ test_decoding’ plugin. Now if the
> > ‘include_generated_columns’ option is specified, the generated column
> > information and generated column data also will be sent.
>
> As Euler mentioned earlier, I think it's a decision not to replicate
> generated columns because we don't know the target table on the
> subscriber has the same expression and there could be locale issues
> even if it looks the same. I can see that a benefit of this proposal
> would be to save cost to compute generated column values if the user
> wants the target table on the subscriber to have exactly the same data
> as the publisher's one. Are there other benefits or use cases?

I think this will be useful mainly for the use cases where the
publisher has generated columns and the subscriber does not have
generated  columns.
In the case where both the publisher and subscriber have generated
columns, the current patch will overwrite the generated column values
based on the expression for the generated column in the subscriber.

> >
> > Usage from pgoutput plugin:
> > CREATE TABLE gencoltable (a int PRIMARY KEY, b int GENERATED ALWAYS AS
> > (a * 2) STORED);
> > CREATE publication pub1 for all tables;
> > SELECT 'init' FROM pg_create_logical_replication_slot('slot1', 'pgoutput');
> > SELECT * FROM pg_logical_slot_peek_binary_changes('slot1', NULL, NULL,
> > 'proto_version', '1', 'publication_names', 'pub1',
> > 'include_generated_columns', 'true');
> >
> > Usage from test_decoding plugin:
> > SELECT 'init' FROM pg_create_logical_replication_slot('slot2', 
> > 'test_decoding');
> > CREATE TABLE gencoltable (a int PRIMARY KEY, b int GENERATED ALWAYS AS
> > (a * 2) STORED);
> > INSERT INTO gencoltable (a) VALUES (1), (2), (3);
> > SELECT data FROM pg_logical_slot_get_changes('slot2', NULL, NULL,
> > 'include-xids', '0', 'skip-empty-xacts', '1',
> > 'include_generated_columns', '1');
> >
> > Currently it is not supported as a subscription option because table
> > sync for the generated column is not possible as copy command does not
> > support getting data for the generated column. If this feature is
> > required we can remove this limitation from the copy command and then
> > add it as a subscription option later.
> > Thoughts?
>
> I think that if we want to support an option to replicate generated
> columns, the initial tablesync should support it too. Otherwise, we
> end up filling the target columns data with NULL during the initial
> tablesync but with replicated data during the streaming changes.

+1 for supporting initial sync.
Currently copy_data = true and generate_column = true are not
supported, this limitation will be removed in one of the upcoming
patches.

Regards,
Vignesh




Re: using extended statistics to improve join estimates

2024-05-20 Thread Andy Fan


Hi Andrei,

> On 4/3/24 01:22, Tomas Vondra wrote:
>> Cool! There's obviously no chance to get this into v18, and I have stuff
>> to do in this CF. But I'll take a look after that.
> I'm looking at your patch now - an excellent start to an eagerly awaited
> feature!
> A couple of questions:
> 1. I didn't find the implementation of strategy 'c' - estimation by the
> number of distinct values. Do you forget it?

What do you mean the "strategy 'c'"?  

> 2. Can we add a clauselist selectivity hook into the core (something
> similar the code in attachment)? It can allow the development and
> testing of multicolumn join estimations without patching the core.

The idea LGTM. But do you want 

+   if (clauselist_selectivity_hook)
+   s1 = clauselist_selectivity_hook(root, clauses, varRelid, 
jointype,
+

rather than

+   if (clauselist_selectivity_hook)
+   *return* clauselist_selectivity_hook(root, clauses, ..)


?

-- 
Best Regards
Andy Fan





Re: POC: GROUP BY optimization

2024-05-20 Thread jian he
On Thu, May 16, 2024 at 3:47 PM Andrei Lepikhov
 wrote:
>
> On 24.04.2024 13:25, jian he wrote:
> > hi.
> > I found an interesting case.
> >
> > CREATE TABLE t1 AS
> >SELECT (i % 10)::numeric AS x,(i % 10)::int8 AS y,'abc' || i % 10 AS
> > z, i::int4 AS w
> >FROM generate_series(1, 100) AS i;
> > CREATE INDEX t1_x_y_idx ON t1 (x, y);
> > ANALYZE t1;
> > SET enable_hashagg = off;
> > SET enable_seqscan = off;
> >
> > EXPLAIN (COSTS OFF) SELECT count(*) FROM t1 GROUP BY x,z,y,w;
> > EXPLAIN (COSTS OFF) SELECT count(*) FROM t1 GROUP BY x,w,y,z;
> > EXPLAIN (COSTS OFF) SELECT count(*) FROM t1 GROUP BY x,z,w,y;
> > EXPLAIN (COSTS OFF) SELECT count(*) FROM t1 GROUP BY x,w,z,y;
> > the above part will use:
> >->  Incremental Sort
> >   Sort Key: x, $, $, $
> >   Presorted Key: x
> >   ->  Index Scan using t1_x_y_idx on t1
> >
> > EXPLAIN (COSTS OFF) SELECT count(*) FROM t1 GROUP BY z,y,w,x;
> > EXPLAIN (COSTS OFF) SELECT count(*) FROM t1 GROUP BY w,y,z,x;
> > EXPLAIN (COSTS OFF) SELECT count(*) FROM t1 GROUP BY y,z,x,w;
> > EXPLAIN (COSTS OFF) SELECT count(*) FROM t1 GROUP BY y,w,x,z;
> > EXPLAIN (COSTS OFF) SELECT count(*) FROM t1 GROUP BY y,x,z,w;
> > EXPLAIN (COSTS OFF) SELECT count(*) FROM t1 GROUP BY y,x,w,z;
> >
> > these will use:
> >->  Incremental Sort
> >   Sort Key: x, y, $, $
> >   Presorted Key: x, y
> >   ->  Index Scan using t1_x_y_idx on t1
> >
> > I guess this is fine, but not optimal?
> It looks like a bug right now - in current implementation we don't
> differentiate different orders. So:
> 1. Applying all the patches from the thread which I proposed as an
> answer to T.Lane last rebuke - does behavior still the same?.

I've applied these 4 patches in  this thread.
final_improvements.patch
minor_comment.patch
get_useful_group_keys_orderings.patch
group_by_asymmetry.diff

The behavior is still the same as the master.
meaning that below quoted queries are still using "Presorted Key: x".

> > EXPLAIN (COSTS OFF) SELECT count(*) FROM t1 GROUP BY x,z,y,w;
> > EXPLAIN (COSTS OFF) SELECT count(*) FROM t1 GROUP BY x,w,y,z;
> > EXPLAIN (COSTS OFF) SELECT count(*) FROM t1 GROUP BY x,z,w,y;
> > EXPLAIN (COSTS OFF) SELECT count(*) FROM t1 GROUP BY x,w,z,y;
> > the above part will use:
> >->  Incremental Sort
> >   Sort Key: x, $, $, $
> >   Presorted Key: x
> >   ->  Index Scan using t1_x_y_idx on t1


> 2. Could you try to find the reason?
the following are my understanding, it may be wrong...

function get_useful_group_keys_orderings, may generate alternative
pathkeys and group clauses.
for different PathKeyInfo
sub functions within add_paths_to_grouping_rel:
make_ordered_path, create_agg_path will yield the same cost.
function add_path (within add_paths_to_grouping_rel) will add these
paths (different PathKeyInfos) in a *sequential* order.

then later in the function set_cheapest.
`foreach(p, parent_rel->pathlist)`  will iterate these different paths
in a sequential order.
so in set_cheapest if 2 path costs are the same, then the first path
residing in parent_rel->pathlist wins.


fo a concrete example:
CREATE TABLE t1 AS
SELECT (i % 10)::numeric AS x,(i % 10)::int8 AS y,'abc' || i % 10 AS
z, i::float4 AS w FROM generate_series(1, 100) AS i;
CREATE INDEX t1_x_y_idx ON t1 (x, y);
ANALYZE t1;
SET enable_hashagg = off;
SET enable_seqscan = off;
EXPLAIN (COSTS OFF, verbose) SELECT count(*) FROM t1 GROUP BY x,z,y,w;

add_paths_to_grouping_rel will do the following in a sequential order.
A. generate and add original PathKeyInfo(groupby x,z,y,w)
B. generate and add alternative PathKeyInfo(groupby x,y,z,w). (because
of the index path)
C. can_hash is true, generate a HashAgg Path (because of
enable_hashagg is set to off, so this path the cost is very high)

As mentioned previously,
both A and B can use Incremental Sort, set_cheapest will choose the A
instead of B,
because A step generated path **first** satisfies increment sort.




Re: using extended statistics to improve join estimates

2024-05-20 Thread Andrei Lepikhov

On 4/3/24 01:22, Tomas Vondra wrote:

Cool! There's obviously no chance to get this into v18, and I have stuff
to do in this CF. But I'll take a look after that.
I'm looking at your patch now - an excellent start to an eagerly awaited 
feature!

A couple of questions:
1. I didn't find the implementation of strategy 'c' - estimation by the 
number of distinct values. Do you forget it?
2. Can we add a clauselist selectivity hook into the core (something 
similar the code in attachment)? It can allow the development and 
testing of multicolumn join estimations without patching the core.


--
regards,
Andrei Lepikhov
Postgres Professional
diff --git a/src/backend/optimizer/path/clausesel.c b/src/backend/optimizer/path/clausesel.c
index 0ab021c1e8..271d36a522 100644
--- a/src/backend/optimizer/path/clausesel.c
+++ b/src/backend/optimizer/path/clausesel.c
@@ -128,6 +128,9 @@ clauselist_selectivity_ext(PlannerInfo *root,
 	ListCell   *l;
 	int			listidx;
 
+	if (clauselist_selectivity_hook)
+		s1 = clauselist_selectivity_hook(root, clauses, varRelid, jointype,
+		 sjinfo, );
 	/*
 	 * If there's exactly one clause, just go directly to
 	 * clause_selectivity_ext(). None of what we might do below is relevant.
diff --git a/src/backend/utils/adt/selfuncs.c b/src/backend/utils/adt/selfuncs.c
index 5f5d7959d8..ff98fda08c 100644
--- a/src/backend/utils/adt/selfuncs.c
+++ b/src/backend/utils/adt/selfuncs.c
@@ -146,6 +146,7 @@
 /* Hooks for plugins to get control when we ask for stats */
 get_relation_stats_hook_type get_relation_stats_hook = NULL;
 get_index_stats_hook_type get_index_stats_hook = NULL;
+clauselist_selectivity_hook_type clauselist_selectivity_hook = NULL;
 
 static double eqsel_internal(PG_FUNCTION_ARGS, bool negate);
 static double eqjoinsel_inner(Oid opfuncoid, Oid collation,
diff --git a/src/include/utils/selfuncs.h b/src/include/utils/selfuncs.h
index f2563ad1cb..ee28d3ba9b 100644
--- a/src/include/utils/selfuncs.h
+++ b/src/include/utils/selfuncs.h
@@ -148,6 +148,15 @@ typedef bool (*get_index_stats_hook_type) (PlannerInfo *root,
 		   VariableStatData *vardata);
 extern PGDLLIMPORT get_index_stats_hook_type get_index_stats_hook;
 
+/* Hooks for plugins to get control when we ask for selectivity estimation */
+typedef bool (*clauselist_selectivity_hook_type) (PlannerInfo *root,
+  List *clauses,
+  int varRelid,
+  JoinType jointype,
+  SpecialJoinInfo *sjinfo,
+  Bitmapset **estimatedclauses);
+extern PGDLLIMPORT clauselist_selectivity_hook_type clauselist_selectivity_hook;
+
 /* Functions in selfuncs.c */
 
 extern void examine_variable(PlannerInfo *root, Node *node, int varRelid,


Re: Pgoutput not capturing the generated columns

2024-05-20 Thread Masahiko Sawada
Hi,

On Wed, May 8, 2024 at 4:14 PM Shubham Khanna
 wrote:
>
> On Wed, May 8, 2024 at 11:39 AM Rajendra Kumar Dangwal
>  wrote:
> >
> > Hi PG Hackers.
> >
> > We are interested in enhancing the functionality of the pgoutput plugin by 
> > adding support for generated columns.
> > Could you please guide us on the necessary steps to achieve this? 
> > Additionally, do you have a platform for tracking such feature requests? 
> > Any insights or assistance you can provide on this matter would be greatly 
> > appreciated.
>
> The attached patch has the changes to support capturing generated
> column data using ‘pgoutput’ and’ test_decoding’ plugin. Now if the
> ‘include_generated_columns’ option is specified, the generated column
> information and generated column data also will be sent.

As Euler mentioned earlier, I think it's a decision not to replicate
generated columns because we don't know the target table on the
subscriber has the same expression and there could be locale issues
even if it looks the same. I can see that a benefit of this proposal
would be to save cost to compute generated column values if the user
wants the target table on the subscriber to have exactly the same data
as the publisher's one. Are there other benefits or use cases?

>
> Usage from pgoutput plugin:
> CREATE TABLE gencoltable (a int PRIMARY KEY, b int GENERATED ALWAYS AS
> (a * 2) STORED);
> CREATE publication pub1 for all tables;
> SELECT 'init' FROM pg_create_logical_replication_slot('slot1', 'pgoutput');
> SELECT * FROM pg_logical_slot_peek_binary_changes('slot1', NULL, NULL,
> 'proto_version', '1', 'publication_names', 'pub1',
> 'include_generated_columns', 'true');
>
> Usage from test_decoding plugin:
> SELECT 'init' FROM pg_create_logical_replication_slot('slot2', 
> 'test_decoding');
> CREATE TABLE gencoltable (a int PRIMARY KEY, b int GENERATED ALWAYS AS
> (a * 2) STORED);
> INSERT INTO gencoltable (a) VALUES (1), (2), (3);
> SELECT data FROM pg_logical_slot_get_changes('slot2', NULL, NULL,
> 'include-xids', '0', 'skip-empty-xacts', '1',
> 'include_generated_columns', '1');
>
> Currently it is not supported as a subscription option because table
> sync for the generated column is not possible as copy command does not
> support getting data for the generated column. If this feature is
> required we can remove this limitation from the copy command and then
> add it as a subscription option later.
> Thoughts?

I think that if we want to support an option to replicate generated
columns, the initial tablesync should support it too. Otherwise, we
end up filling the target columns data with NULL during the initial
tablesync but with replicated data during the streaming changes.

Regards,

--
Masahiko Sawada
Amazon Web Services: https://aws.amazon.com




Re: commitfest.postgresql.org is no longer fit for purpose

2024-05-20 Thread Daniel Gustafsson
> On 20 May 2024, at 07:49, Thomas Munro  wrote:

> We're actually
> halfway to Gitlab et al already, with a web account and interaction
> required to start the process of submitting a patch for consideration.

Another Web<->Mailinglist extreme is Git themselves who have a Github bridge
for integration with their usual patch-on-mailinglist workflow.

https://github.com/gitgitgadget/gitgitgadget

> What I'm less clear on is who else has come up with the "bitrot" test
> idea, either at the mailing list or web extremist ends of the scale.

Most web based platforms like Github register the patch against the tree at the
time of submitting, and won't refresh unless the user does so.  Github does
detect bitrot and show a "this cannot be merged" error message, but it doesn't
alter any state on the PR etc.

--
Daniel Gustafsson





Re: Proposal for Updating CRC32C with AVX-512 Algorithm.

2024-05-20 Thread Daniel Gustafsson
> On 17 May 2024, at 18:21, Amonson, Paul D  wrote:

> Hi, forgive the top-post but I have not seen any response to this post?

The project is currently in feature-freeze in preparation for the next major
release so new development and ideas are not the top priority right now.
Additionally there is a large developer meeting shortly which many are busy
preparing for.  Excercise some patience, and I'm sure there will be follow-ups
to this once development of postgres v18 picks up.

--
Daniel Gustafsson





Re: State of pg_createsubscriber

2024-05-20 Thread Michael Paquier
On Sun, May 19, 2024 at 02:49:22PM -0300, Euler Taveira wrote:
> My bad. :( I'll post patches soon to address all of the points.

Please note that I have added an open item pointing at this thread.
--
Michael


signature.asc
Description: PGP signature


Convert node test compile-time settings into run-time parameters

2024-05-20 Thread Peter Eisentraut

This patch converts the compile-time settings

COPY_PARSE_PLAN_TREES
WRITE_READ_PARSE_PLAN_TREES
RAW_EXPRESSION_COVERAGE_TEST

into run-time parameters

debug_copy_parse_plan_trees
debug_write_read_parse_plan_trees
debug_raw_expression_coverage_test

They can be activated for tests using PG_TEST_INITDB_EXTRA_OPTS.

The effect is the same, but now you don't need to recompile in order to 
use these checks.


The compile-time symbols are kept for build farm compatibility, but they 
now just determine the default value of the run-time settings.


Possible concerns:

- Performance?  Looking for example at pg_parse_query() and its 
siblings, they also check for other debugging settings like 
log_parser_stats in the main code path, so it doesn't seem to be a concern.


- Access control?  I have these settings as PGC_USERSET for now. Maybe 
they should be PGC_SUSET?


Another thought:  Do we really need three separate settings?
From 568c620eb97f82aa8eab850cb3ce703c5c94a912 Mon Sep 17 00:00:00 2001
From: Peter Eisentraut 
Date: Mon, 20 May 2024 09:13:23 +0200
Subject: [PATCH v1] Convert node test compile-time settings into run-time
 parameters

This converts

COPY_PARSE_PLAN_TREES
WRITE_READ_PARSE_PLAN_TREES
RAW_EXPRESSION_COVERAGE_TEST

into run-time parameters

debug_copy_parse_plan_trees
debug_write_read_parse_plan_trees
debug_raw_expression_coverage_test

They can be activated for tests using PG_TEST_INITDB_EXTRA_OPTS.

The compile-time symbols are kept for build farm compatibility, but
they now just determine the default value of the run-time settings.

TODO: config.sgml documentation
---
 .cirrus.tasks.yml   |  3 +-
 src/backend/nodes/README|  9 ++---
 src/backend/nodes/read.c| 15 +---
 src/backend/nodes/readfuncs.c   | 10 +-
 src/backend/parser/analyze.c| 14 +++-
 src/backend/tcop/postgres.c | 18 --
 src/backend/utils/misc/guc_tables.c | 55 +
 src/include/nodes/nodes.h   |  2 --
 src/include/nodes/readfuncs.h   |  2 --
 src/include/pg_config_manual.h  | 21 ---
 src/include/utils/guc.h |  4 +++
 11 files changed, 79 insertions(+), 74 deletions(-)

diff --git a/.cirrus.tasks.yml b/.cirrus.tasks.yml
index a2388cd5036..6a9ff066391 100644
--- a/.cirrus.tasks.yml
+++ b/.cirrus.tasks.yml
@@ -133,9 +133,10 @@ task:
 DISK_SIZE: 50
 
 CCACHE_DIR: /tmp/ccache_dir
-CPPFLAGS: -DRELCACHE_FORCE_RELEASE -DCOPY_PARSE_PLAN_TREES 
-DWRITE_READ_PARSE_PLAN_TREES -DRAW_EXPRESSION_COVERAGE_TEST 
-DENFORCE_REGRESSION_TEST_NAME_RESTRICTIONS
+CPPFLAGS: -DRELCACHE_FORCE_RELEASE 
-DENFORCE_REGRESSION_TEST_NAME_RESTRICTIONS
 CFLAGS: -Og -ggdb
 
+PG_TEST_INITDB_EXTRA_OPTS: -c debug_copy_parse_plan_trees=on -c 
debug_write_read_parse_plan_trees=on -c debug_raw_expression_coverage_test=on
 PG_TEST_PG_UPGRADE_MODE: --link
 
   <<: *freebsd_task_template
diff --git a/src/backend/nodes/README b/src/backend/nodes/README
index 52364470205..f8bbd605386 100644
--- a/src/backend/nodes/README
+++ b/src/backend/nodes/README
@@ -98,10 +98,11 @@ Suppose you want to define a node Foo:
node types to find all the places to touch.
(Except for frequently-created nodes, don't bother writing a creator
function in makefuncs.c.)
-4. Consider testing your new code with COPY_PARSE_PLAN_TREES,
-   WRITE_READ_PARSE_PLAN_TREES, and RAW_EXPRESSION_COVERAGE_TEST to ensure
-   support has been added everywhere that it's necessary; see
-   pg_config_manual.h about these.
+4. Consider testing your new code with debug_copy_parse_plan_trees,
+   debug_write_read_parse_plan_trees, and
+   debug_raw_expression_coverage_test to ensure support has been added
+   everywhere that it's necessary (e.g., run the tests with
+   PG_TEST_INITDB_EXTRA_OPTS='-c debug_...=on').
 
 Adding a new node type moves the numbers associated with existing
 tags, so you'll need to recompile the whole tree after doing this.
diff --git a/src/backend/nodes/read.c b/src/backend/nodes/read.c
index 4eb42445c52..e2d2ce7374d 100644
--- a/src/backend/nodes/read.c
+++ b/src/backend/nodes/read.c
@@ -32,9 +32,7 @@
 static const char *pg_strtok_ptr = NULL;
 
 /* State flag that determines how readfuncs.c should treat location fields */
-#ifdef WRITE_READ_PARSE_PLAN_TREES
 bool   restore_location_fields = false;
-#endif
 
 
 /*
@@ -42,17 +40,14 @@ boolrestore_location_fields = false;
  *   builds a Node tree from its string representation (assumed valid)
  *
  * restore_loc_fields instructs readfuncs.c whether to restore location
- * fields rather than set them to -1.  This is currently only supported
- * in builds with the WRITE_READ_PARSE_PLAN_TREES debugging flag set.
+ * fields rather than set them to -1.
  */
 static void *
 stringToNodeInternal(const char *str, bool restore_loc_fields)
 {
void   *retval;
const char *save_strtok;

Re: Schema variables - new implementation for Postgres 15

2024-05-20 Thread Pavel Stehule
so 18. 5. 2024 v 18:31 odesílatel Alvaro Herrera 
napsal:

> On 2024-Jan-30, Dmitry Dolgov wrote:
>
> > Yep, in this constellation the implementation holds much better (in
> > terms of memory) in my create/let/drop testing.
> >
> > I've marked the CF item as ready for committer, but a note for anyone
> > who would like to pick up it from here -- we're talking about first 5
> > patches here, up to the memory cleaning after DROP VARIABLE. It doesn't
> > mean the rest is somehow not worth it, but I believe it's a good first
> > step.
>
> Hmm, I think patch 16 is essential, because the point of variable shadowing
> is a critical aspect of how the whole thing works.  So I would say that
> a first step would be those first five patches plus 16.
>

I'll move patch 16 to 6 position

Regards

Pavel

>
> I want to note that when we discussed this patch series at the dev
> meeting in FOSDEM, a sort-of conclusion was reached that we didn't want
> schema variables at all because of the fact that creating a variable
> would potentially change the meaning of queries by shadowing table
> columns.  But this turns out to be incorrect: it's _variables_ that are
> shadowed by table columns, not the other way around.
>
> --
> Álvaro Herrera PostgreSQL Developer  —
> https://www.EnterpriseDB.com/
> "No hay ausente sin culpa ni presente sin disculpa" (Prov. francés)
>


Re: PostgreSQL 17 Beta 1 release announcement draft

2024-05-20 Thread John Naylor
Hi Jon,

Regarding vacuum "has shown up to a 6x improvement in overall time to
complete its work" -- I believe I've seen reported numbers close to
that only 1) when measuring the index phase in isolation or maybe 2)
the entire vacuum of unlogged tables with one, perfectly-correlated
index (testing has less variance with WAL out of the picture). I
believe tables with many indexes would show a lot of improvement, but
I'm not aware of testing that case specifically. Can you clarify where
6x came from?




Re: Pgoutput not capturing the generated columns

2024-05-20 Thread Shlok Kyal
Hi Kuroda-san,

Thanks for reviewing the patch. I have fixed some of the comments
> 2.
> Currently, the option is implemented as streaming option. Are there any 
> reasons
> to choose the way? Another approach is to implement as slot option, like 
> failover
> and temporary.
I think the current approach is appropriate. The options such as
failover and temporary seem like properties of a slot and I think
decoding of generated column should not be slot specific. Also adding
a new option for slot may create an overhead.

> 3.
> You said that subscription option is not supported for now. Not sure, is it 
> mean
> that logical replication feature cannot be used for generated columns? If so,
> the restriction won't be acceptable. If the combination between this and 
> initial
> sync is problematic, can't we exclude them in CreateSubscrition and 
> AlterSubscription?
> E.g., create_slot option cannot be set if slot_name is NONE.
Added an option 'generated_column' for create subscription. Currently
it allow to set 'generated_column' option as true only if 'copy_data'
is set to false.
Also we don't allow user to alter the 'generated_column' option.

> 6. logicalrep_write_tuple()
>
> ```
> -if (!column_in_column_list(att->attnum, columns))
> +if (!column_in_column_list(att->attnum, columns) && 
> !att->attgenerated)
> +continue;
> ```
>
> Hmm, does above mean that generated columns are decoded even if they are not 
> in
> the column list? If so, why? I think such columns should not be sent.
Fixed

Thanks and Regards,
Shlok Kyal


v2-0001-Support-generated-column-capturing-generated-colu.patch
Description: Binary data


Re: State of pg_createsubscriber

2024-05-20 Thread Amit Kapila
On Sun, May 19, 2024 at 11:20 PM Euler Taveira  wrote:
>
> On Sun, May 19, 2024, at 2:30 PM, Tom Lane wrote:
>
> I'm fairly disturbed about the readiness of pg_createsubscriber.
> The 040_pg_createsubscriber.pl TAP test is moderately unstable
> in the buildfarm [1], and there are various unaddressed complaints
> at the end of the patch thread (pretty much everything below [2]).
> I guess this is good enough to start beta with, but it's far from
> being good enough to ship, IMO.  If there were active work going
> on to fix these things, I'd feel better, but neither the C code
> nor the test script have been touched since 1 April.
>
>
> My bad. :( I'll post patches soon to address all of the points.
>

Just to summarize, apart from BF failures for which we had some
discussion, I could recall the following open points:

1. After promotion, the pre-existing replication objects should be
removed (either optionally or always), otherwise, it can lead to a new
subscriber not being able to restart or getting some unwarranted data.
[1][2].

2. Retaining synced slots on new subscribers can lead to unnecessary
WAL retention and dead rows [3].

3. We need to consider whether some of the messages displayed in
--dry-run mode are useful or not [4].

[1] - 
https://www.postgresql.org/message-id/CAA4eK1L6HOhT1qifTyuestXkPpkRwY9bOqFd4wydKsN6C3hePA%40mail.gmail.com
[2] - 
https://www.postgresql.org/message-id/flat/3fa9ef0f-b277-4c13-850a-8ccc04de1406%40eisentraut.org#152dacecfc8f0cf08cbd8ecb79d6d38f
[3] - 
https://www.postgresql.org/message-id/CAA4eK1KdCb%2B5sjYu6qCMXXdCX1y_ihr8kFzMozq0%3DP%3DauYxgog%40mail.gmail.com
[4] - 
https://www.postgresql.org/message-id/flat/3fa9ef0f-b277-4c13-850a-8ccc04de1406%40eisentraut.org#152dacecfc8f0cf08cbd8ecb79d6d38f

-- 
With Regards,
Amit Kapila.




Re: First draft of PG 17 release notes

2024-05-20 Thread John Naylor
Hi Bruce, thanks for doing this again!

I'm a bit late to this discussion -- there's been a bit of churn in
the vacuum items, and some streams got crossed along the way. I've
attached an attempt to rectify this.
diff --git a/doc/src/sgml/release-17.sgml b/doc/src/sgml/release-17.sgml
index 0e7ff51f4a..612eb100a7 100644
--- a/doc/src/sgml/release-17.sgml
+++ b/doc/src/sgml/release-17.sgml
@@ -492,23 +492,23 @@ Allow BRIN indexes to be created using parallel workers (Tomas Vondra, Matthias
  
 
 
 
 
 
-Allow vacuum to more efficiently remove and freeze tuples (Masahiko Sawada, John Naylor, Melanie Plageman)
+Allow vacuum to more efficiently remove and freeze tuples (Melanie Plageman)
+
+
+
+WAL traffic caused by vacuum is also more compact.
 
 
 
 

Re: Lowering the minimum value for maintenance_work_mem

2024-05-20 Thread John Naylor
On Mon, May 20, 2024 at 11:59 AM Masahiko Sawada  wrote:
>
> On Fri, May 17, 2024 at 5:55 AM Andres Freund  wrote:

> > I think we should consider lowering the minimum setting of
> > maintenance_work_mem to the minimum of work_mem.
>
> +1 for lowering the minimum value of maintenance_work_mem. I've faced
> the same situation.
>
> Even if a shared tidstore is empty, TidStoreMemoryUsage() returns
> 256kB because it's the minimum segment size of DSA, i.e.
> DSA_MIN_SEGMENT_SIZE. So we can lower the minimum maintenance_work_mem
> down to 256kB, from a vacuum perspective.

I've verified 256kB works with both local and shared memory with the
below commands, and 200k records are enough to cause a second round of
index cleanup. I don't think we can go much smaller than that without
changing how we size the blocks in the node slab contexts (or when
they're created), which is currently somewhat arbitrary. That'll need
some thought, at least when we get a use case with work_mem as the
limit.

set maintenance_work_mem = '256kB';

drop table if exists test;
create unlogged table test (a int) with (autovacuum_enabled=false);
insert into test (a) select i from generate_series(1,200_000) i;
create index on test (a);
--create index on test (a); -- toggle for parallel vacuum

delete from test;
vacuum (verbose) test;

Side note: I'm confused why shared memory works at all in this case,
since it failed for 1MB init segments until we allowed callers to
specify a smaller init size. The overhead for DSA seems to be
significant for small sizes, as evidenced from the amount of usable
memory:

shared:
INFO:  finished vacuuming "john.public.test": index scans: 56

local:
INFO:  finished vacuuming "john.public.test": index scans: 2




  1   2   >