Skip to content
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

Initial work on COPY progress - take two. #5

Closed
wants to merge 20 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
c47a240
Fix checksum calculation in the new sorting GiST build.
hlinnaka Sep 21, 2020
80fc96e
Standardize order of use strict and use warnings in Perl code
petere Sep 21, 2020
9436041
Copy editing: fix a bunch of misspellings and poor wording.
tglsfdc Sep 21, 2020
f859c2f
Fix a few more generator scripts to produce pgindent-clean output.
tglsfdc Sep 21, 2020
ce90f07
Improve the error message for an inappropriate column definition list.
tglsfdc Sep 22, 2020
c4133ec
Exclude fmgrprotos.h from pgindent processing.
tglsfdc Sep 22, 2020
9314870
Rethink API for pg_get_line.c, one more time.
tglsfdc Sep 22, 2020
c0cb87f
Remove arbitrary line length limit for libpq service files.
tglsfdc Sep 22, 2020
2e3c194
Simplify SortTocFromFile() by removing fixed buffer-size limit.
tglsfdc Sep 22, 2020
733fa9a
Allow WaitLatch() to be used without a latch.
macdice Sep 23, 2020
3ea7e95
Avoid possible dangling-pointer access in tsearch_readline_callback.
tglsfdc Sep 23, 2020
6b2c4e5
Improve error cursor positions for problems with partition bounds.
tglsfdc Sep 23, 2020
aca7484
Fix missing fsync of SLRU directories.
macdice Sep 23, 2020
83b6131
Improve behavior of tsearch_readline(), and remove t_readline().
tglsfdc Sep 24, 2020
fc5f107
Doc: sync lobj.sgml's copy of testlo.c with the latter file.
tglsfdc Sep 24, 2020
f5ea92e
Expose oldSnapshotControl definition via new header.
robertmhaas Sep 24, 2020
aecf5ee
Add new 'old_snapshot' contrib module.
robertmhaas Sep 24, 2020
01a187a
Initial work on COPY progress.
simi Jun 8, 2020
6d62a8d
Enhance copy progress with more info.
simi Jun 14, 2020
8eff7b4
Support STDIN, STDOUT. Add docs.
simi Jun 21, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions contrib/Makefile
Expand Up @@ -27,6 +27,7 @@ SUBDIRS = \
lo \
ltree \
oid2name \
old_snapshot \
pageinspect \
passwordcheck \
pg_buffercache \
Expand Down
22 changes: 22 additions & 0 deletions contrib/old_snapshot/Makefile
@@ -0,0 +1,22 @@
# contrib/old_snapshot/Makefile

MODULE_big = old_snapshot
OBJS = \
$(WIN32RES) \
time_mapping.o
PG_CPPFLAGS = -I$(libpq_srcdir)

EXTENSION = old_snapshot
DATA = old_snapshot--1.0.sql
PGFILEDESC = "old_snapshot - utilities in support of old_snapshot_threshold"

ifdef USE_PGXS
PG_CONFIG = pg_config
PGXS := $(shell $(PG_CONFIG) --pgxs)
include $(PGXS)
else
subdir = contrib/old_snapshot
top_builddir = ../..
include $(top_builddir)/src/Makefile.global
include $(top_srcdir)/contrib/contrib-global.mk
endif
14 changes: 14 additions & 0 deletions contrib/old_snapshot/old_snapshot--1.0.sql
@@ -0,0 +1,14 @@
/* contrib/old_snapshot/old_snapshot--1.0.sql */

-- complain if script is sourced in psql, rather than via CREATE EXTENSION
\echo Use "CREATE EXTENSION old_snapshot" to load this file. \quit

-- Show visibility map and page-level visibility information for each block.
CREATE FUNCTION pg_old_snapshot_time_mapping(array_offset OUT int4,
end_timestamp OUT timestamptz,
newest_xmin OUT xid)
RETURNS SETOF record
AS 'MODULE_PATHNAME', 'pg_old_snapshot_time_mapping'
LANGUAGE C STRICT;

-- XXX. Do we want REVOKE commands here?
5 changes: 5 additions & 0 deletions contrib/old_snapshot/old_snapshot.control
@@ -0,0 +1,5 @@
# old_snapshot extension
comment = 'utilities in support of old_snapshot_threshold'
default_version = '1.0'
module_pathname = '$libdir/old_snapshot'
relocatable = true
159 changes: 159 additions & 0 deletions contrib/old_snapshot/time_mapping.c
@@ -0,0 +1,159 @@
/*-------------------------------------------------------------------------
*
* time_mapping.c
* time to XID mapping information
*
* Copyright (c) 2020, PostgreSQL Global Development Group
*
* contrib/old_snapshot/time_mapping.c
*-------------------------------------------------------------------------
*/
#include "postgres.h"

#include "funcapi.h"
#include "storage/lwlock.h"
#include "utils/old_snapshot.h"
#include "utils/snapmgr.h"
#include "utils/timestamp.h"

/*
* Backend-private copy of the information from oldSnapshotControl which relates
* to the time to XID mapping, plus an index so that we can iterate.
*
* Note that the length of the xid_by_minute array is given by
* OLD_SNAPSHOT_TIME_MAP_ENTRIES (which is not a compile-time constant).
*/
typedef struct
{
int current_index;
int head_offset;
TimestampTz head_timestamp;
int count_used;
TransactionId xid_by_minute[FLEXIBLE_ARRAY_MEMBER];
} OldSnapshotTimeMapping;

#define NUM_TIME_MAPPING_COLUMNS 3

PG_MODULE_MAGIC;
PG_FUNCTION_INFO_V1(pg_old_snapshot_time_mapping);

static OldSnapshotTimeMapping *GetOldSnapshotTimeMapping(void);
static TupleDesc MakeOldSnapshotTimeMappingTupleDesc(void);
static HeapTuple MakeOldSnapshotTimeMappingTuple(TupleDesc tupdesc,
OldSnapshotTimeMapping *mapping);

/*
* SQL-callable set-returning function.
*/
Datum
pg_old_snapshot_time_mapping(PG_FUNCTION_ARGS)
{
FuncCallContext *funcctx;
OldSnapshotTimeMapping *mapping;

if (SRF_IS_FIRSTCALL())
{
MemoryContext oldcontext;

funcctx = SRF_FIRSTCALL_INIT();
oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx);
mapping = GetOldSnapshotTimeMapping();
funcctx->user_fctx = mapping;
funcctx->tuple_desc = MakeOldSnapshotTimeMappingTupleDesc();
MemoryContextSwitchTo(oldcontext);
}

funcctx = SRF_PERCALL_SETUP();
mapping = (OldSnapshotTimeMapping *) funcctx->user_fctx;

while (mapping->current_index < mapping->count_used)
{
HeapTuple tuple;

tuple = MakeOldSnapshotTimeMappingTuple(funcctx->tuple_desc, mapping);
++mapping->current_index;
SRF_RETURN_NEXT(funcctx, HeapTupleGetDatum(tuple));
}

SRF_RETURN_DONE(funcctx);
}

/*
* Get the old snapshot time mapping data from shared memory.
*/
static OldSnapshotTimeMapping *
GetOldSnapshotTimeMapping(void)
{
OldSnapshotTimeMapping *mapping;

mapping = palloc(offsetof(OldSnapshotTimeMapping, xid_by_minute)
+ sizeof(TransactionId) * OLD_SNAPSHOT_TIME_MAP_ENTRIES);
mapping->current_index = 0;

LWLockAcquire(OldSnapshotTimeMapLock, LW_SHARED);
mapping->head_offset = oldSnapshotControl->head_offset;
mapping->head_timestamp = oldSnapshotControl->head_timestamp;
mapping->count_used = oldSnapshotControl->count_used;
for (int i = 0; i < OLD_SNAPSHOT_TIME_MAP_ENTRIES; ++i)
mapping->xid_by_minute[i] = oldSnapshotControl->xid_by_minute[i];
LWLockRelease(OldSnapshotTimeMapLock);

return mapping;
}

/*
* Build a tuple descriptor for the pg_old_snapshot_time_mapping() SRF.
*/
static TupleDesc
MakeOldSnapshotTimeMappingTupleDesc(void)
{
TupleDesc tupdesc;

tupdesc = CreateTemplateTupleDesc(NUM_TIME_MAPPING_COLUMNS);

TupleDescInitEntry(tupdesc, (AttrNumber) 1, "array_offset",
INT4OID, -1, 0);
TupleDescInitEntry(tupdesc, (AttrNumber) 2, "end_timestamp",
TIMESTAMPTZOID, -1, 0);
TupleDescInitEntry(tupdesc, (AttrNumber) 3, "newest_xmin",
XIDOID, -1, 0);

return BlessTupleDesc(tupdesc);
}

/*
* Convert one entry from the old snapshot time mapping to a HeapTuple.
*/
static HeapTuple
MakeOldSnapshotTimeMappingTuple(TupleDesc tupdesc, OldSnapshotTimeMapping *mapping)
{
Datum values[NUM_TIME_MAPPING_COLUMNS];
bool nulls[NUM_TIME_MAPPING_COLUMNS];
int array_position;
TimestampTz timestamp;

/*
* Figure out the array position corresponding to the current index.
*
* Index 0 means the oldest entry in the mapping, which is stored at
* mapping->head_offset. Index 1 means the next-oldest entry, which is a the
* following index, and so on. We wrap around when we reach the end of the array.
*/
array_position = (mapping->head_offset + mapping->current_index)
% OLD_SNAPSHOT_TIME_MAP_ENTRIES;

/*
* No explicit timestamp is stored for any entry other than the oldest one,
* but each entry corresponds to 1-minute period, so we can just add.
*/
timestamp = TimestampTzPlusMilliseconds(mapping->head_timestamp,
mapping->current_index * 60000);

/* Initialize nulls and values arrays. */
memset(nulls, 0, sizeof(nulls));
values[0] = Int32GetDatum(array_position);
values[1] = TimestampTzGetDatum(timestamp);
values[2] = TransactionIdGetDatum(mapping->xid_by_minute[array_position]);

return heap_form_tuple(tupdesc, values, nulls);
}
2 changes: 1 addition & 1 deletion doc/src/sgml/btree.sgml
Expand Up @@ -642,7 +642,7 @@ options(<replaceable>relopts</replaceable> <type>local_relopts *</type>) returns
</para>
<para>
Deduplication works by periodically merging groups of duplicate
tuples together, forming a single posting list tuple for each
tuples together, forming a single <firstterm>posting list</firstterm> tuple for each
group. The column key value(s) only appear once in this
representation. This is followed by a sorted array of
<acronym>TID</acronym>s that point to rows in the table. This
Expand Down
3 changes: 2 additions & 1 deletion doc/src/sgml/catalogs.sgml
Expand Up @@ -7298,7 +7298,8 @@ SCRAM-SHA-256$<replaceable>&lt;iteration count&gt;</replaceable>:<replaceable>&l
of statistics accumulated for this statistics object by
<xref linkend="sql-analyze"/>.
A zero value indicates that no statistics should be collected.
A negative value says to use the system default statistics target.
A negative value says to use the maximum of the statistics targets of
the referenced columns, if set, or the system default statistics target.
Positive values of <structfield>stxstattarget</structfield>
determine the target number of <quote>most common values</quote>
to collect.
Expand Down
22 changes: 11 additions & 11 deletions doc/src/sgml/config.sgml
Expand Up @@ -3813,7 +3813,7 @@ restore_command = 'copy "C:\\server\\archivedir\\%f" "%p"' # Windows
servers or streaming base backup clients (i.e., the maximum number of
simultaneously running WAL sender processes). The default is
<literal>10</literal>. The value <literal>0</literal> means
replication is disabled. Abrupt streaming client disconnection might
replication is disabled. Abrupt disconnection of a streaming client might
leave an orphaned connection slot behind until a timeout is reached,
so this parameter should be set slightly higher than the maximum
number of expected clients so disconnected clients can immediately
Expand Down Expand Up @@ -3902,9 +3902,9 @@ restore_command = 'copy "C:\\server\\archivedir\\%f" "%p"' # Windows
slots</link> are allowed to retain in the <filename>pg_wal</filename>
directory at checkpoint time.
If <varname>max_slot_wal_keep_size</varname> is -1 (the default),
replication slots retain unlimited amount of WAL files. If
restart_lsn of a replication slot gets behind more than that megabytes
from the current LSN, the standby using the slot may no longer be able
replication slots may retain an unlimited amount of WAL files. Otherwise, if
restart_lsn of a replication slot falls behind the current LSN by more
than the given size, the standby using the slot may no longer be able
to continue replication due to removal of required WAL files. You
can see the WAL availability of replication slots
in <link linkend="view-pg-replication-slots">pg_replication_slots</link>.
Expand Down Expand Up @@ -6847,9 +6847,9 @@ log_line_prefix = '%m [%p] %q%u@%d/%a '
</term>
<listitem>
<para>
If greater than zero, each bind parameter value reported in
non-error statement-logging messages is trimmed to this many bytes.
Zero disables logging bind parameters with statements.
If greater than zero, each bind parameter value logged with a
non-error statement-logging message is trimmed to this many bytes.
Zero disables logging of bind parameters for non-error statement logs.
<literal>-1</literal> (the default) allows bind parameters to be
logged in full.
If this value is specified without units, it is taken as bytes.
Expand Down Expand Up @@ -8224,10 +8224,10 @@ COPY postgres_log FROM '/full/path/to/logfile.csv' WITH csv;
a regular <command>VACUUM</command> in that it visits every page that might
contain unfrozen XIDs or MXIDs, not just those that might contain dead
tuples. The default is 150 million transactions. Although users can
set this value anywhere from zero to two billions, <command>VACUUM</command>
set this value anywhere from zero to two billion, <command>VACUUM</command>
will silently limit the effective value to 95% of
<xref linkend="guc-autovacuum-freeze-max-age"/>, so that a
periodical manual <command>VACUUM</command> has a chance to run before an
periodic manual <command>VACUUM</command> has a chance to run before an
anti-wraparound autovacuum is launched for the table. For more
information see
<xref linkend="vacuum-for-wraparound"/>.
Expand Down Expand Up @@ -8271,10 +8271,10 @@ COPY postgres_log FROM '/full/path/to/logfile.csv' WITH csv;
a regular <command>VACUUM</command> in that it visits every page that might
contain unfrozen XIDs or MXIDs, not just those that might contain dead
tuples. The default is 150 million multixacts.
Although users can set this value anywhere from zero to two billions,
Although users can set this value anywhere from zero to two billion,
<command>VACUUM</command> will silently limit the effective value to 95% of
<xref linkend="guc-autovacuum-multixact-freeze-max-age"/>, so that a
periodical manual <command>VACUUM</command> has a chance to run before an
periodic manual <command>VACUUM</command> has a chance to run before an
anti-wraparound is launched for the table.
For more information see <xref linkend="vacuum-for-multixact-wraparound"/>.
</para>
Expand Down
1 change: 1 addition & 0 deletions doc/src/sgml/contrib.sgml
Expand Up @@ -116,6 +116,7 @@ CREATE EXTENSION <replaceable>module_name</replaceable>;
&isn;
&lo;
&ltree;
&oldsnapshot;
&pageinspect;
&passwordcheck;
&pgbuffercache;
Expand Down
2 changes: 1 addition & 1 deletion doc/src/sgml/ddl.sgml
Expand Up @@ -3992,7 +3992,7 @@ ALTER TABLE measurement ATTACH PARTITION measurement_y2008m02
Before running the <command>ATTACH PARTITION</command> command, it is
recommended to create a <literal>CHECK</literal> constraint on the table to
be attached matching the desired partition constraint. That way,
the system will be able to skip the scan to validate the implicit
the system will be able to skip the scan which is otherwise needed to validate the implicit
partition constraint. Without the <literal>CHECK</literal> constraint,
the table will be scanned to validate the partition constraint while
holding an <literal>ACCESS EXCLUSIVE</literal> lock on that partition
Expand Down
1 change: 1 addition & 0 deletions doc/src/sgml/filelist.sgml
Expand Up @@ -129,6 +129,7 @@
<!ENTITY lo SYSTEM "lo.sgml">
<!ENTITY ltree SYSTEM "ltree.sgml">
<!ENTITY oid2name SYSTEM "oid2name.sgml">
<!ENTITY oldsnapshot SYSTEM "oldsnapshot.sgml">
<!ENTITY pageinspect SYSTEM "pageinspect.sgml">
<!ENTITY passwordcheck SYSTEM "passwordcheck.sgml">
<!ENTITY pgbuffercache SYSTEM "pgbuffercache.sgml">
Expand Down
4 changes: 2 additions & 2 deletions doc/src/sgml/func.sgml
Expand Up @@ -15626,11 +15626,11 @@ table2-mapping
<literal>'use_json_null'</literal>.
</para>
<para>
<literal>jsonb_set_lax('[{"f1":1,"f2":null},2,null,3]', '{0,f1}',null)</literal>
<literal>jsonb_set_lax('[{"f1":1,"f2":null},2,null,3]', '{0,f1}', null)</literal>
<returnvalue>[{"f1":null,"f2":null},2,null,3]</returnvalue>
</para>
<para>
<literal>jsonb_set_lax('[{"f1":99,"f2":null},2]', '{0,f3}',null, true, 'return_target')</literal>
<literal>jsonb_set_lax('[{"f1":99,"f2":null},2]', '{0,f3}', null, true, 'return_target')</literal>
<returnvalue>[{"f1": 99, "f2": null}, 2]</returnvalue>
</para></entry>
</row>
Expand Down
2 changes: 1 addition & 1 deletion doc/src/sgml/generate-errcodes-table.pl
Expand Up @@ -3,8 +3,8 @@
# Generate the errcodes-table.sgml file from errcodes.txt
# Copyright (c) 2000-2020, PostgreSQL Global Development Group

use warnings;
use strict;
use warnings;

print
"<!-- autogenerated from src/backend/utils/errcodes.txt, do not edit -->\n";
Expand Down
2 changes: 1 addition & 1 deletion doc/src/sgml/libpq.sgml
Expand Up @@ -1227,7 +1227,7 @@ postgresql://%2Fvar%2Flib%2Fpostgresql/dbname
<term><literal>connect_timeout</literal></term>
<listitem>
<para>
Maximum wait for connection, in seconds (write as a decimal integer,
Maximum time to wait while connecting, in seconds (write as a decimal integer,
e.g., <literal>10</literal>). Zero, negative, or not specified means
wait indefinitely. The minimum allowed timeout is 2 seconds, therefore
a value of <literal>1</literal> is interpreted as <literal>2</literal>.
Expand Down
2 changes: 0 additions & 2 deletions doc/src/sgml/lobj.sgml
Expand Up @@ -901,8 +901,6 @@ exportFile(PGconn *conn, Oid lobjId, char *filename)

lo_close(conn, lobj_fd);
close(fd);

return;
}

static void
Expand Down
2 changes: 1 addition & 1 deletion doc/src/sgml/logical-replication.sgml
Expand Up @@ -403,7 +403,7 @@
<listitem>
<para>
Replication is only supported by tables, including partitioned tables.
Attempts to replicate other types of relations such as views, materialized
Attempts to replicate other types of relations, such as views, materialized
views, or foreign tables, will result in an error.
</para>
</listitem>
Expand Down