pg.ddx.io pgsql-committers@postgresql.org mailing list archive
help / color / mirror / Atom feedpgsql: Exclude unlogged tables from base backups
8+ messages / 3 participants
[nested] [flat]
Commits from this thread:
2018-03-25 d0c0c89453 Fix unsafe extraction of the OID part of a relation filename.
* pgsql: Exclude unlogged tables from base backups
@ 2018-03-23 16:14 Teodor Sigaev <teodor@sigaev.ru>
2018-03-25 18:16 ` Re: pgsql: Exclude unlogged tables from base backups Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 1 reply; 8+ messages in thread
From: Teodor Sigaev @ 2018-03-23 16:14 UTC (permalink / raw)
To: pgsql-committers@lists.postgresql.org
Exclude unlogged tables from base backups
Exclude unlogged tables from base backup entirely except init fork which marks
created unlogged table. The next question is do not backup temp table but
it's a story for separate patch.
Author: David Steele
Review by: Adam Brightwell, Masahiko Sawada
Discussion: https://www.postgresql.org/message-id/flat/04791bab-cb04-ba43-e9c0-664a4c1ffb2c@pgmasters.net
Branch
------
master
Details
-------
https://git.postgresql.org/pg/commitdiff/8694cc96b52a967a49725f32be7aa77fd3b6ac25
Modified Files
--------------
doc/src/sgml/protocol.sgml | 6 +++
src/backend/replication/basebackup.c | 64 ++++++++++++++++++++++++++++
src/backend/storage/file/reinit.c | 4 +-
src/bin/pg_basebackup/t/010_pg_basebackup.pl | 42 +++++++++++++++++-
src/include/storage/reinit.h | 2 +
5 files changed, 113 insertions(+), 5 deletions(-)
^ permalink raw reply [nested|flat] 8+ messages in thread
* Re: pgsql: Exclude unlogged tables from base backups
2018-03-23 16:14 pgsql: Exclude unlogged tables from base backups Teodor Sigaev <teodor@sigaev.ru>
@ 2018-03-25 18:16 ` Tom Lane <tgl@sss.pgh.pa.us>
2018-03-25 19:10 ` Re: pgsql: Exclude unlogged tables from base backups David Steele <david@pgmasters.net>
2018-03-25 19:16 ` Re: pgsql: Exclude unlogged tables from base backups Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 2 replies; 8+ messages in thread
From: Tom Lane @ 2018-03-25 18:16 UTC (permalink / raw)
To: Teodor Sigaev <teodor@sigaev.ru>; David Steele <david@pgmasters.net>; +Cc: pgsql-committers@lists.postgresql.org
Teodor Sigaev <teodor@sigaev.ru> writes:
> Exclude unlogged tables from base backups
Buildfarm member skink (valgrind) has reported this during its last couple
of runs:
2018-03-24 03:18:23.409 UTC [17302] 010_pg_basebackup.pl LOG: received replication command: BASE_BACKUP LABEL 'pg_basebackup base backup' NOWAIT TABLESPACE_MAP
==17302== VALGRINDERROR-BEGIN
==17302== Conditional jump or move depends on uninitialised value(s)
==17302== at 0x4C2FD88: strlen (vg_replace_strmem.c:458)
==17302== by 0x6FBA3AB: vfprintf (vfprintf.c:1643)
==17302== by 0x6FE19AF: vsnprintf (vsnprintf.c:114)
==17302== by 0x6FC0F6E: snprintf (snprintf.c:33)
==17302== by 0x4A3C97: sendDir (basebackup.c:1060)
==17302== by 0x4A40C6: sendDir (basebackup.c:1221)
==17302== by 0x4A52B2: sendTablespace (basebackup.c:937)
==17302== by 0x4A5740: perform_base_backup (basebackup.c:313)
==17302== by 0x4A635C: SendBaseBackup (basebackup.c:710)
==17302== by 0x49FCF2: exec_replication_command (walsender.c:1520)
==17302== by 0x4F61CE: PostgresMain (postgres.c:4143)
==17302== by 0x4712ED: BackendRun (postmaster.c:4409)
==17302== Uninitialised value was created by a stack allocation
==17302== at 0x4A38EA: sendDir (basebackup.c:957)
==17302==
==17302== VALGRINDERROR-END
2018-03-24 03:18:26.127 UTC [17302] 010_pg_basebackup.pl DEBUG: contents of directory "pg_serial" excluded from backup
I might be wrong to blame that on this patch, but nothing else has
touched basebackup.c lately.
regards, tom lane
^ permalink raw reply [nested|flat] 8+ messages in thread
* Re: pgsql: Exclude unlogged tables from base backups
2018-03-23 16:14 pgsql: Exclude unlogged tables from base backups Teodor Sigaev <teodor@sigaev.ru>
2018-03-25 18:16 ` Re: pgsql: Exclude unlogged tables from base backups Tom Lane <tgl@sss.pgh.pa.us>
@ 2018-03-25 19:10 ` David Steele <david@pgmasters.net>
2018-03-25 19:22 ` Re: pgsql: Exclude unlogged tables from base backups Tom Lane <tgl@sss.pgh.pa.us>
1 sibling, 1 reply; 8+ messages in thread
From: David Steele @ 2018-03-25 19:10 UTC (permalink / raw)
To: Tom Lane <tgl@sss.pgh.pa.us>; Teodor Sigaev <teodor@sigaev.ru>; +Cc: pgsql-committers@lists.postgresql.org
On 3/25/18 2:16 PM, Tom Lane wrote:
> Teodor Sigaev <teodor@sigaev.ru> writes:
>> Exclude unlogged tables from base backups
>
> Buildfarm member skink (valgrind) has reported this during its last couple
> of runs:
>
> 2018-03-24 03:18:23.409 UTC [17302] 010_pg_basebackup.pl LOG: received replication command: BASE_BACKUP LABEL 'pg_basebackup base backup' NOWAIT TABLESPACE_MAP
> ==17302== VALGRINDERROR-BEGIN
> ==17302== Conditional jump or move depends on uninitialised value(s)
> ==17302== at 0x4C2FD88: strlen (vg_replace_strmem.c:458)
> ==17302== by 0x6FBA3AB: vfprintf (vfprintf.c:1643)
> ==17302== by 0x6FE19AF: vsnprintf (vsnprintf.c:114)
> ==17302== by 0x6FC0F6E: snprintf (snprintf.c:33)
> ==17302== by 0x4A3C97: sendDir (basebackup.c:1060)
> ==17302== by 0x4A40C6: sendDir (basebackup.c:1221)
> ==17302== by 0x4A52B2: sendTablespace (basebackup.c:937)
> ==17302== by 0x4A5740: perform_base_backup (basebackup.c:313)
> ==17302== by 0x4A635C: SendBaseBackup (basebackup.c:710)
> ==17302== by 0x49FCF2: exec_replication_command (walsender.c:1520)
> ==17302== by 0x4F61CE: PostgresMain (postgres.c:4143)
> ==17302== by 0x4712ED: BackendRun (postmaster.c:4409)
> ==17302== Uninitialised value was created by a stack allocation
> ==17302== at 0x4A38EA: sendDir (basebackup.c:957)
> ==17302==
> ==17302== VALGRINDERROR-END
> 2018-03-24 03:18:26.127 UTC [17302] 010_pg_basebackup.pl DEBUG: contents of directory "pg_serial" excluded from backup
>
> I might be wrong to blame that on this patch, but nothing else has
> touched basebackup.c lately.
Sure looks like it deserves the blame -- the error is occurring right in
the new code.
I think skink is using large values for rel oids and that has exposed a
bug. The strncpy doesn't zero terminate the string if the oid has the
max number of characters. At least, I was able to reproduce under those
circumstances.
The attached should fix it.
Regards,
--
-David
david@pgmasters.net
Attachments:
basebackup.patch (text/plain, 619B) download
diff --git a/src/backend/replication/basebackup.c b/src/backend/replication/basebackup.c
index eb6eb7206d..e368943494 100644
--- a/src/backend/replication/basebackup.c
+++ b/src/backend/replication/basebackup.c
@@ -1056,6 +1056,7 @@ sendDir(const char *path, int basepathlen, bool sizeonly, List *tablespaces,
* If any other type of fork, check if there is an init fork
* with the same OID. If so, the file can be excluded.
*/
+ memset(relOid, 0, sizeof(relOid));
strncpy(relOid, de->d_name, relOidChars);
snprintf(initForkFile, sizeof(initForkFile), "%s/%s_init",
path, relOid);
^ permalink raw reply [nested|flat] 8+ messages in thread
* Re: pgsql: Exclude unlogged tables from base backups
2018-03-23 16:14 pgsql: Exclude unlogged tables from base backups Teodor Sigaev <teodor@sigaev.ru>
2018-03-25 18:16 ` Re: pgsql: Exclude unlogged tables from base backups Tom Lane <tgl@sss.pgh.pa.us>
2018-03-25 19:10 ` Re: pgsql: Exclude unlogged tables from base backups David Steele <david@pgmasters.net>
@ 2018-03-25 19:22 ` Tom Lane <tgl@sss.pgh.pa.us>
2018-03-25 19:46 ` Re: pgsql: Exclude unlogged tables from base backups David Steele <david@pgmasters.net>
0 siblings, 1 reply; 8+ messages in thread
From: Tom Lane @ 2018-03-25 19:22 UTC (permalink / raw)
To: David Steele <david@pgmasters.net>; +Cc: Teodor Sigaev <teodor@sigaev.ru>; pgsql-committers@lists.postgresql.org
David Steele <david@pgmasters.net> writes:
> On 3/25/18 2:16 PM, Tom Lane wrote:
>> Buildfarm member skink (valgrind) has reported this during its last couple
>> of runs:
> I think skink is using large values for rel oids and that has exposed a
> bug. The strncpy doesn't zero terminate the string if the oid has the
> max number of characters. At least, I was able to reproduce under those
> circumstances.
Actually, that code didn't guarantee zero termination under *any*
circumstances; it only happened to work if the stack contained
zeroes to start with.
> The attached should fix it.
Found this in my inbox right after pushing a fix. I did it slightly
differently, emulating the later rather than earlier calls in reinit.c.
The earlier ones memset the whole target field because they're concerned
about being able to hash it, but we don't need that here, just zero
termination.
regards, tom lane
^ permalink raw reply [nested|flat] 8+ messages in thread
* Re: pgsql: Exclude unlogged tables from base backups
2018-03-23 16:14 pgsql: Exclude unlogged tables from base backups Teodor Sigaev <teodor@sigaev.ru>
2018-03-25 18:16 ` Re: pgsql: Exclude unlogged tables from base backups Tom Lane <tgl@sss.pgh.pa.us>
2018-03-25 19:10 ` Re: pgsql: Exclude unlogged tables from base backups David Steele <david@pgmasters.net>
2018-03-25 19:22 ` Re: pgsql: Exclude unlogged tables from base backups Tom Lane <tgl@sss.pgh.pa.us>
@ 2018-03-25 19:46 ` David Steele <david@pgmasters.net>
2018-03-25 19:54 ` Re: pgsql: Exclude unlogged tables from base backups Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 1 reply; 8+ messages in thread
From: David Steele @ 2018-03-25 19:46 UTC (permalink / raw)
To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: Teodor Sigaev <teodor@sigaev.ru>; pgsql-committers@lists.postgresql.org
On 3/25/18 3:22 PM, Tom Lane wrote:
> David Steele <david@pgmasters.net> writes:
>> On 3/25/18 2:16 PM, Tom Lane wrote:
>>> Buildfarm member skink (valgrind) has reported this during its last couple
>>> of runs:
>
>> I think skink is using large values for rel oids and that has exposed a
>> bug. The strncpy doesn't zero terminate the string if the oid has the
>> max number of characters. At least, I was able to reproduce under those
>> circumstances.
>
> Actually, that code didn't guarantee zero termination under *any*
> circumstances; it only happened to work if the stack contained
> zeroes to start with.
Interesting. strncpy() says it will pad the destination with NULLs when
src is less than the size provided. Perhaps some compilers don't honor
that?
>> The attached should fix it.
>
> Found this in my inbox right after pushing a fix. I did it slightly
> differently, emulating the later rather than earlier calls in reinit.c.
> The earlier ones memset the whole target field because they're concerned
> about being able to hash it, but we don't need that here, just zero
> termination.
Yeah, that's the way I would normally do it, but when I searched
reinit.c the first few hits did memset() so I went with that.
Thanks for taking care of it.
--
-David
david@pgmasters.net
^ permalink raw reply [nested|flat] 8+ messages in thread
* Re: pgsql: Exclude unlogged tables from base backups
2018-03-23 16:14 pgsql: Exclude unlogged tables from base backups Teodor Sigaev <teodor@sigaev.ru>
2018-03-25 18:16 ` Re: pgsql: Exclude unlogged tables from base backups Tom Lane <tgl@sss.pgh.pa.us>
2018-03-25 19:10 ` Re: pgsql: Exclude unlogged tables from base backups David Steele <david@pgmasters.net>
2018-03-25 19:22 ` Re: pgsql: Exclude unlogged tables from base backups Tom Lane <tgl@sss.pgh.pa.us>
2018-03-25 19:46 ` Re: pgsql: Exclude unlogged tables from base backups David Steele <david@pgmasters.net>
@ 2018-03-25 19:54 ` Tom Lane <tgl@sss.pgh.pa.us>
2018-03-25 19:59 ` Re: pgsql: Exclude unlogged tables from base backups David Steele <david@pgmasters.net>
0 siblings, 1 reply; 8+ messages in thread
From: Tom Lane @ 2018-03-25 19:54 UTC (permalink / raw)
To: David Steele <david@pgmasters.net>; +Cc: Teodor Sigaev <teodor@sigaev.ru>; pgsql-committers@lists.postgresql.org
David Steele <david@pgmasters.net> writes:
> On 3/25/18 3:22 PM, Tom Lane wrote:
>> Actually, that code didn't guarantee zero termination under *any*
>> circumstances; it only happened to work if the stack contained
>> zeroes to start with.
> Interesting. strncpy() says it will pad the destination with NULLs when
> src is less than the size provided. Perhaps some compilers don't honor
> that?
Yeah, but the "size provided" was the number of characters to be copied
from the source string, not the size of the destination buffer. So
strncpy didn't think it needed to add any nulls. There's a reason why
that function is widely disliked --- it's hard to use it in a safe way.
regards, tom lane
^ permalink raw reply [nested|flat] 8+ messages in thread
* Re: pgsql: Exclude unlogged tables from base backups
2018-03-23 16:14 pgsql: Exclude unlogged tables from base backups Teodor Sigaev <teodor@sigaev.ru>
2018-03-25 18:16 ` Re: pgsql: Exclude unlogged tables from base backups Tom Lane <tgl@sss.pgh.pa.us>
2018-03-25 19:10 ` Re: pgsql: Exclude unlogged tables from base backups David Steele <david@pgmasters.net>
2018-03-25 19:22 ` Re: pgsql: Exclude unlogged tables from base backups Tom Lane <tgl@sss.pgh.pa.us>
2018-03-25 19:46 ` Re: pgsql: Exclude unlogged tables from base backups David Steele <david@pgmasters.net>
2018-03-25 19:54 ` Re: pgsql: Exclude unlogged tables from base backups Tom Lane <tgl@sss.pgh.pa.us>
@ 2018-03-25 19:59 ` David Steele <david@pgmasters.net>
0 siblings, 0 replies; 8+ messages in thread
From: David Steele @ 2018-03-25 19:59 UTC (permalink / raw)
To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: Teodor Sigaev <teodor@sigaev.ru>; pgsql-committers@lists.postgresql.org
On 3/25/18 3:54 PM, Tom Lane wrote:
> David Steele <david@pgmasters.net> writes:
>> On 3/25/18 3:22 PM, Tom Lane wrote:
>>> Actually, that code didn't guarantee zero termination under *any*
>>> circumstances; it only happened to work if the stack contained
>>> zeroes to start with.
>
>> Interesting. strncpy() says it will pad the destination with NULLs when
>> src is less than the size provided. Perhaps some compilers don't honor
>> that?
>
> Yeah, but the "size provided" was the number of characters to be copied
> from the source string, not the size of the destination buffer. So
> strncpy didn't think it needed to add any nulls. There's a reason why
> that function is widely disliked --- it's hard to use it in a safe way.
Whoops, how right you are. I'm generally passing destination buffer
size in these cases and totally misread what this was doing.
--
-David
david@pgmasters.net
^ permalink raw reply [nested|flat] 8+ messages in thread
* Re: pgsql: Exclude unlogged tables from base backups
2018-03-23 16:14 pgsql: Exclude unlogged tables from base backups Teodor Sigaev <teodor@sigaev.ru>
2018-03-25 18:16 ` Re: pgsql: Exclude unlogged tables from base backups Tom Lane <tgl@sss.pgh.pa.us>
@ 2018-03-25 19:16 ` Tom Lane <tgl@sss.pgh.pa.us>
1 sibling, 0 replies; 8+ messages in thread
From: Tom Lane @ 2018-03-25 19:16 UTC (permalink / raw)
To: Teodor Sigaev <teodor@sigaev.ru>; David Steele <david@pgmasters.net>; +Cc: pgsql-committers@lists.postgresql.org
I wrote:
> I might be wrong to blame that on this patch, but nothing else has
> touched basebackup.c lately.
Ah, I see the problem, I think. Fixed.
regards, tom lane
^ permalink raw reply [nested|flat] 8+ messages in thread
end of thread, other threads:[~2018-03-25 19:59 UTC | newest]
Thread overview: 8+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2018-03-23 16:14 pgsql: Exclude unlogged tables from base backups Teodor Sigaev <teodor@sigaev.ru>
2018-03-25 18:16 ` Tom Lane <tgl@sss.pgh.pa.us>
2018-03-25 19:10 ` David Steele <david@pgmasters.net>
2018-03-25 19:22 ` Tom Lane <tgl@sss.pgh.pa.us>
2018-03-25 19:46 ` David Steele <david@pgmasters.net>
2018-03-25 19:54 ` Tom Lane <tgl@sss.pgh.pa.us>
2018-03-25 19:59 ` David Steele <david@pgmasters.net>
2018-03-25 19:16 ` Tom Lane <tgl@sss.pgh.pa.us>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox