Skip to content

[pull] master from postgres:master #1008

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Jul 1, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion contrib/amcheck/verify_heapam.c
Original file line number Diff line number Diff line change
Expand Up @@ -1942,7 +1942,7 @@ check_tuple(HeapCheckContext *ctx, bool *xmin_commit_status_ok,
if (RelationGetDescr(ctx->rel)->natts < ctx->natts)
{
report_corruption(ctx,
psprintf("number of attributes %u exceeds maximum expected for table %u",
psprintf("number of attributes %u exceeds maximum %u expected for table",
ctx->natts,
RelationGetDescr(ctx->rel)->natts));
return;
Expand Down
3 changes: 1 addition & 2 deletions contrib/pg_buffercache/pg_buffercache_pages.c
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,6 @@ pg_buffercache_numa_pages(PG_FUNCTION_ARGS)
uint64 os_page_count;
int pages_per_buffer;
int max_entries;
volatile uint64 touch pg_attribute_unused();
char *startptr,
*endptr;

Expand Down Expand Up @@ -375,7 +374,7 @@ pg_buffercache_numa_pages(PG_FUNCTION_ARGS)

/* Only need to touch memory once per backend process lifetime */
if (firstNumaTouch)
pg_numa_touch_mem_if_required(touch, ptr);
pg_numa_touch_mem_if_required(ptr);
}

Assert(idx == os_page_count);
Expand Down
4 changes: 2 additions & 2 deletions doc/src/sgml/amcheck.sgml
Original file line number Diff line number Diff line change
Expand Up @@ -278,8 +278,8 @@ SET client_min_messages = DEBUG1;
TOAST table.
</para>
<para>
This option is known to be slow. Also, if the toast table or its
index is corrupt, checking it against toast values could conceivably
This option is known to be slow. Also, if the TOAST table or its
index is corrupt, checking it against TOAST values could conceivably
crash the server, although in many cases this would just produce an
error.
</para>
Expand Down
2 changes: 1 addition & 1 deletion doc/src/sgml/bki.sgml
Original file line number Diff line number Diff line change
Expand Up @@ -1042,7 +1042,7 @@ $ perl rewrite_dat_with_prokind.pl pg_proc.dat
</listitem>
<listitem>
<para>
Define indexes and toast tables.
Define indexes and TOAST tables.
</para>
</listitem>
<listitem>
Expand Down
2 changes: 1 addition & 1 deletion doc/src/sgml/catalogs.sgml
Original file line number Diff line number Diff line change
Expand Up @@ -1951,7 +1951,7 @@ SCRAM-SHA-256$<replaceable>&lt;iteration count&gt;</replaceable>:<replaceable>&l
</para>
<para>
The OID of the data type that corresponds to this table's row type,
if any; zero for indexes, sequences, and toast tables, which have
if any; zero for indexes, sequences, and TOAST tables, which have
no <structname>pg_type</structname> entry
</para></entry>
</row>
Expand Down
8 changes: 2 additions & 6 deletions doc/src/sgml/installation.sgml
Original file line number Diff line number Diff line change
Expand Up @@ -3847,17 +3847,13 @@ make: *** [postgres] Error 1
<para>
Both 32-bit and 64-bit builds are possible with the Microsoft Compiler suite.
32-bit PostgreSQL builds are possible with
<productname>Visual Studio 2015</productname> to
<productname>Visual Studio 2019</productname> to
<productname>Visual Studio 2022</productname>,
as well as standalone Windows SDK releases 10 and above.
64-bit PostgreSQL builds are supported with
<productname>Microsoft Windows SDK</productname> version 10 and above or
<productname>Visual Studio 2015</productname> and above.
<productname>Visual Studio 2019</productname> and above.
<!--
For 2015 requirements:
https://docs.microsoft.com/en-us/visualstudio/productinfo/vs2015-sysrequirements-vs
For 2017 requirements:
https://docs.microsoft.com/en-us/visualstudio/productinfo/vs2017-system-requirements-vs
For 2019 requirements:
https://docs.microsoft.com/en-us/visualstudio/releases/2019/system-requirements
For 2022 requirements:
Expand Down
2 changes: 1 addition & 1 deletion doc/src/sgml/logicaldecoding.sgml
Original file line number Diff line number Diff line change
Expand Up @@ -1412,7 +1412,7 @@ commit_prepared_cb(...); &lt;-- commit of the prepared transaction
currently used for decoded changes) is selected and streamed. However, in
some cases we still have to spill to disk even if streaming is enabled
because we exceed the memory threshold but still have not decoded the
complete tuple e.g., only decoded toast table insert but not the main table
complete tuple e.g., only decoded TOAST table insert but not the main table
insert.
</para>

Expand Down
2 changes: 1 addition & 1 deletion doc/src/sgml/ref/alter_table.sgml
Original file line number Diff line number Diff line change
Expand Up @@ -852,7 +852,7 @@ WITH ( MODULUS <replaceable class="parameter">numeric_literal</replaceable>, REM

<para>
<literal>SHARE UPDATE EXCLUSIVE</literal> lock will be taken for
fillfactor, toast and autovacuum storage parameters, as well as the
fillfactor, TOAST and autovacuum storage parameters, as well as the
planner parameter <varname>parallel_workers</varname>.
</para>
</listitem>
Expand Down
12 changes: 6 additions & 6 deletions doc/src/sgml/ref/pg_amcheck.sgml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ PostgreSQL documentation
</para>

<para>
Only ordinary and toast table relations, materialized views, sequences, and
Only ordinary and TOAST table relations, materialized views, sequences, and
btree indexes are currently supported. Other relation types are silently
skipped.
</para>
Expand Down Expand Up @@ -276,7 +276,7 @@ PostgreSQL documentation
<term><option>--no-dependent-toast</option></term>
<listitem>
<para>
By default, if a table is checked, its toast table, if any, will also
By default, if a table is checked, its TOAST table, if any, will also
be checked, even if it is not explicitly selected by an option
such as <literal>--table</literal> or <literal>--relation</literal>.
This option suppresses that behavior.
Expand Down Expand Up @@ -306,9 +306,9 @@ PostgreSQL documentation
<term><option>--exclude-toast-pointers</option></term>
<listitem>
<para>
By default, whenever a toast pointer is encountered in a table,
By default, whenever a TOAST pointer is encountered in a table,
a lookup is performed to ensure that it references apparently-valid
entries in the toast table. These checks can be quite slow, and this
entries in the TOAST table. These checks can be quite slow, and this
option can be used to skip them.
</para>
</listitem>
Expand Down Expand Up @@ -368,9 +368,9 @@ PostgreSQL documentation
End checking at the specified block number. An error will occur if the
table relation being checked has fewer than this number of blocks.
This option does not apply to indexes, and is probably only useful when
checking a single table relation. If both a regular table and a toast
checking a single table relation. If both a regular table and a TOAST
table are checked, this option will apply to both, but higher-numbered
toast blocks may still be accessed while validating toast pointers,
TOAST blocks may still be accessed while validating TOAST pointers,
unless that is suppressed using
<option>--exclude-toast-pointers</option>.
</para>
Expand Down
2 changes: 1 addition & 1 deletion doc/src/sgml/sepgsql.sgml
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ UPDATE t1 SET x = 2, y = func1(y) WHERE z = 100;
<para>
The default database privilege system allows database superusers to
modify system catalogs using DML commands, and reference or modify
toast tables. These operations are prohibited when
TOAST tables. These operations are prohibited when
<filename>sepgsql</filename> is enabled.
</para>
</sect3>
Expand Down
4 changes: 4 additions & 0 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,10 @@ elif host_system == 'windows'
# define before including <time.h> for getting localtime_r() etc. on MinGW
cppflags += '-D_POSIX_C_SOURCE'
endif
if cc.get_id() == 'msvc'
# required for VA_ARGS_NARGS() in c.h; requires VS 2019
cppflags += '/Zc:preprocessor'
endif

export_file_format = 'win'
export_file_suffix = 'def'
Expand Down
4 changes: 1 addition & 3 deletions src/backend/storage/ipc/shmem.c
Original file line number Diff line number Diff line change
Expand Up @@ -679,12 +679,10 @@ pg_get_shmem_allocations_numa(PG_FUNCTION_ARGS)
*/
for (i = 0; i < shm_ent_page_count; i++)
{
volatile uint64 touch pg_attribute_unused();

page_ptrs[i] = startptr + (i * os_page_size);

if (firstNumaTouch)
pg_numa_touch_mem_if_required(touch, page_ptrs[i]);
pg_numa_touch_mem_if_required(page_ptrs[i]);

CHECK_FOR_INTERRUPTS();
}
Expand Down
4 changes: 2 additions & 2 deletions src/bin/pg_amcheck/t/004_verify_heapam.pl
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,7 @@ sub header
$tup->{t_infomask2} |= HEAP_NATTS_MASK;

push @expected,
qr/${$header}number of attributes 2047 exceeds maximum expected for table 3/;
qr/${$header}number of attributes 2047 exceeds maximum 3 expected for table/;
}
elsif ($offnum == 10)
{
Expand All @@ -552,7 +552,7 @@ sub header
$tup->{t_hoff} = 32;

push @expected,
qr/${$header}number of attributes 67 exceeds maximum expected for table 3/;
qr/${$header}number of attributes 67 exceeds maximum 3 expected for table/;
}
elsif ($offnum == 12)
{
Expand Down
19 changes: 0 additions & 19 deletions src/include/c.h
Original file line number Diff line number Diff line change
Expand Up @@ -376,25 +376,7 @@
* pretty trivial: VA_ARGS_NARGS_() returns its 64th argument, and we set up
* the call so that that is the appropriate one of the list of constants.
* This idea is due to Laurent Deniau.
*
* MSVC has an implementation of __VA_ARGS__ that doesn't conform to the
* standard unless you use the /Zc:preprocessor compiler flag, but that
* isn't available before Visual Studio 2019. For now, use a different
* definition that also works on older compilers.
*/
#ifdef _MSC_VER
#define EXPAND(args) args
#define VA_ARGS_NARGS(...) \
VA_ARGS_NARGS_ EXPAND((__VA_ARGS__, \
63,62,61,60, \
59,58,57,56,55,54,53,52,51,50, \
49,48,47,46,45,44,43,42,41,40, \
39,38,37,36,35,34,33,32,31,30, \
29,28,27,26,25,24,23,22,21,20, \
19,18,17,16,15,14,13,12,11,10, \
9, 8, 7, 6, 5, 4, 3, 2, 1, 0))
#else

#define VA_ARGS_NARGS(...) \
VA_ARGS_NARGS_(__VA_ARGS__, \
63,62,61,60, \
Expand All @@ -404,7 +386,6 @@
29,28,27,26,25,24,23,22,21,20, \
19,18,17,16,15,14,13,12,11,10, \
9, 8, 7, 6, 5, 4, 3, 2, 1, 0)
#endif

#define VA_ARGS_NARGS_( \
_01,_02,_03,_04,_05,_06,_07,_08,_09,_10, \
Expand Down
2 changes: 1 addition & 1 deletion src/include/catalog/pg_publication.h
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ extern Publication *GetPublicationByName(const char *pubname, bool missing_ok);
extern List *GetRelationPublications(Oid relid);

/*---------
* Expected values for pub_partopt parameter of GetRelationPublications(),
* Expected values for pub_partopt parameter of GetPublicationRelations(),
* which allows callers to specify which partitions of partitioned tables
* mentioned in the publication they expect to see.
*
Expand Down
11 changes: 8 additions & 3 deletions src/include/port/pg_numa.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,17 @@ extern PGDLLIMPORT int pg_numa_get_max_node(void);
* This is required on Linux, before pg_numa_query_pages() as we
* need to page-fault before move_pages(2) syscall returns valid results.
*/
#define pg_numa_touch_mem_if_required(ro_volatile_var, ptr) \
ro_volatile_var = *(volatile uint64 *) ptr
static inline void
pg_numa_touch_mem_if_required(void *ptr)
{
volatile uint64 touch pg_attribute_unused();

touch = *(volatile uint64 *) ptr;
}

#else

#define pg_numa_touch_mem_if_required(ro_volatile_var, ptr) \
#define pg_numa_touch_mem_if_required(ptr) \
do {} while(0)

#endif
Expand Down
53 changes: 52 additions & 1 deletion src/port/pg_numa.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "c.h"
#include <unistd.h>

#include "miscadmin.h"
#include "port/pg_numa.h"

/*
Expand All @@ -29,6 +30,19 @@
#include <numa.h>
#include <numaif.h>

/*
* numa_move_pages() chunk size, has to be <= 16 to work around a kernel bug
* in do_pages_stat() (chunked by DO_PAGES_STAT_CHUNK_NR). By using the same
* chunk size, we make it work even on unfixed kernels.
*
* 64-bit system are not affected by the bug, and so use much larger chunks.
*/
#if SIZEOF_SIZE_T == 4
#define NUMA_QUERY_CHUNK_SIZE 16
#else
#define NUMA_QUERY_CHUNK_SIZE 1024
#endif

/* libnuma requires initialization as per numa(3) on Linux */
int
pg_numa_init(void)
Expand All @@ -42,11 +56,48 @@ pg_numa_init(void)
* We use move_pages(2) syscall here - instead of get_mempolicy(2) - as the
* first one allows us to batch and query about many memory pages in one single
* giant system call that is way faster.
*
* We call numa_move_pages() for smaller chunks of the whole array. The first
* reason is to work around a kernel bug, but also to allow interrupting the
* query between the calls (for many pointers processing the whole array can
* take a lot of time).
*/
int
pg_numa_query_pages(int pid, unsigned long count, void **pages, int *status)
{
return numa_move_pages(pid, count, pages, NULL, status, 0);
unsigned long next = 0;
int ret = 0;

/*
* Chunk pointers passed to numa_move_pages to NUMA_QUERY_CHUNK_SIZE
* items, to work around a kernel bug in do_pages_stat().
*/
while (next < count)
{
unsigned long count_chunk = Min(count - next,
NUMA_QUERY_CHUNK_SIZE);

CHECK_FOR_INTERRUPTS();

/*
* Bail out if any of the chunks errors out (ret<0). We ignore (ret>0)
* which is used to return number of nonmigrated pages, but we're not
* migrating any pages here.
*/
ret = numa_move_pages(pid, count_chunk, &pages[next], NULL, &status[next], 0);
if (ret < 0)
{
/* plain error, return as is */
return ret;
}

next += count_chunk;
}

/* should have consumed the input array exactly */
Assert(next == count);

return 0;
}

int
Expand Down
14 changes: 14 additions & 0 deletions src/tools/valgrind.supp
Original file line number Diff line number Diff line change
Expand Up @@ -180,3 +180,17 @@
Memcheck:Cond
fun:PyObject_Realloc
}

# NUMA introspection requires touching memory first, and some of it may
# be marked as noacess (e.g. unpinned buffers). So just ignore that.
{
pg_numa_touch_mem_if_required
Memcheck:Addr4
fun:pg_numa_touch_mem_if_required
}

{
pg_numa_touch_mem_if_required
Memcheck:Addr8
fun:pg_numa_touch_mem_if_required
}