pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
minor annoyance - search_path not reset in/after dump/restore
4+ messages / 3 participants
[nested] [flat]

* minor annoyance - search_path not reset in/after dump/restore
@ 2017-11-27 14:04  Frank van Vugt <ftm.van.vugt@foxi.nl>
  0 siblings, 1 reply; 4+ messages in thread

From: Frank van Vugt @ 2017-11-27 14:04 UTC (permalink / raw)
  To: pgsql-bugs

L.S.

I'm not sure the following qualifies as a 'real' bug, but since it suprised me, 
I'd like to raise it here, just in case it surprises others as well.

Postgresql version 9.6.6

The default value for the search_path is "$user", public.

Since I'm using schema's, my pg_dump files contain lines like this:
	SET search_path = cnt_user, pg_catalog;
for each particular schema part in the dump.

However, at the end of the dump file, there's nothing to restore the 
search_path to the default / last value.

This means that after restoring a dump via a psql console using a line like:
	\i /tmp/daily-db-backup
the search_path value will be equal to that of the last schema restored...

This causes unexpected output of commands like '\d' afterwards.

Obviously, disconnecting/reconnecting 'fixes' things.



-- 

Thanks,




Frank.





^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: minor annoyance - search_path not reset in/after dump/restore
@ 2018-01-24 02:51  Bruce Momjian <bruce@momjian.us>
  parent: Frank van Vugt <ftm.van.vugt@foxi.nl>
  0 siblings, 1 reply; 4+ messages in thread

From: Bruce Momjian @ 2018-01-24 02:51 UTC (permalink / raw)
  To: Frank van Vugt <ftm.van.vugt@foxi.nl>; +Cc: pgsql-bugs

On Mon, Nov 27, 2017 at 03:04:19PM +0100, Frank van Vugt wrote:
> L.S.
> 
> I'm not sure the following qualifies as a 'real' bug, but since it suprised me, 
> I'd like to raise it here, just in case it surprises others as well.
> 
> Postgresql version 9.6.6
> 
> The default value for the search_path is "$user", public.
> 
> Since I'm using schema's, my pg_dump files contain lines like this:
> 	SET search_path = cnt_user, pg_catalog;
> for each particular schema part in the dump.
> 
> However, at the end of the dump file, there's nothing to restore the 
> search_path to the default / last value.
> 
> This means that after restoring a dump via a psql console using a line like:
> 	\i /tmp/daily-db-backup
> the search_path value will be equal to that of the last schema restored...
> 
> This causes unexpected output of commands like '\d' afterwards.
> 
> Obviously, disconnecting/reconnecting 'fixes' things.

Interesting.  I had not considered someone would include a dump file,
but it makes sense.

The attached patch adds a RESET ALL to the end of the text dump to cause
a reset of all GUC variables.  Does this make sense to folks?  It would
only be applied to head, so it would only appear in PG 11.

-- 
  Bruce Momjian  <bruce@momjian.us>        http://momjian.us
  EnterpriseDB                             http://enterprisedb.com

+ As you are, so once was I.  As I am, so you will be. +
+                      Ancient Roman grave inscription +

Attachments:

reset.diff (text/x-diff, 584B) download diff --git a/src/bin/pg_dump/pg_backup_archiver.c b/src/bin/pg_dump/pg_backup_archiver.c new file mode 100644 index f55aa36..4c28c30 *** a/src/bin/pg_dump/pg_backup_archiver.c --- b/src/bin/pg_dump/pg_backup_archiver.c *************** RestoreArchive(Archive *AHX) *** 721,726 **** --- 721,729 ---- if (AH->public.verbose) dumpTimestamp(AH, "Completed on", time(NULL)); + /* Reset session in case we are included by another session */ + ahprintf(AH, "--\n-- Reset session\n\nRESET ALL;\n\n"); + ahprintf(AH, "--\n-- PostgreSQL database dump complete\n--\n\n"); /*
^ permalink raw reply [nested|flat] 4+ messages in thread

* Re: minor annoyance - search_path not reset in/after dump/restore
@ 2018-01-24 03:45  David G. Johnston <david.g.johnston@gmail.com>
  parent: Bruce Momjian <bruce@momjian.us>
  0 siblings, 1 reply; 4+ messages in thread

From: David G. Johnston @ 2018-01-24 03:45 UTC (permalink / raw)
  To: Bruce Momjian <bruce@momjian.us>; +Cc: Frank van Vugt <ftm.van.vugt@foxi.nl>; pgsql-bugs

On Tuesday, January 23, 2018, Bruce Momjian <bruce@momjian.us> wrote:
>
> The attached patch adds a RESET ALL to the end of the text dump to cause
> a reset of all GUC variables.  Does this make sense to folks?  It would
> only be applied to head, so it would only appear in PG 11.


I'm inclined to take the position that if you are going to do something
like this you should decide how to proceed when the restore completes.
Adding \c or RESET ALL immediately after that \i is straight-forward enough
and at least in the \c case you'd get the effects of any ALTER DATABASE SET
commands in the dump.  Now, usually I would place the \i itself in a file
and not type it interactively...

While I cannot imagine anyone depending on the current behavior it does
encourage one to reconnect to the loaded database regardless of how the
restore happened.

David J.

^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: minor annoyance - search_path not reset in/after dump/restore
@ 2018-01-24 14:47  Bruce Momjian <bruce@momjian.us>
  parent: David G. Johnston <david.g.johnston@gmail.com>
  0 siblings, 0 replies; 4+ messages in thread

From: Bruce Momjian @ 2018-01-24 14:47 UTC (permalink / raw)
  To: David G. Johnston <david.g.johnston@gmail.com>; +Cc: Frank van Vugt <ftm.van.vugt@foxi.nl>; pgsql-bugs

On Tue, Jan 23, 2018 at 08:45:24PM -0700, David G. Johnston wrote:
> On Tuesday, January 23, 2018, Bruce Momjian <bruce@momjian.us> wrote:
> 
>     The attached patch adds a RESET ALL to the end of the text dump to cause
>     a reset of all GUC variables.  Does this make sense to folks?  It would
>     only be applied to head, so it would only appear in PG 11. 
> 
> 
> I'm inclined to take the position that if you are going to do something like
> this you should decide how to proceed when the restore completes.  Adding \c or
> RESET ALL immediately after that \i is straight-forward enough and at least in
> the \c case you'd get the effects of any ALTER DATABASE SET commands in the
> dump.  Now, usually I would place the \i itself in a file and not type it
> interactively...
> 
> While I cannot imagine anyone depending on the current behavior it does
> encourage one to reconnect to the loaded database regardless of how the restore
> happened.

OK, agreed.  A pg_dumpall restore will leave you in a different
database.  I will assume this item is closed.

-- 
  Bruce Momjian  <bruce@momjian.us>        http://momjian.us
  EnterpriseDB                             http://enterprisedb.com

+ As you are, so once was I.  As I am, so you will be. +
+                      Ancient Roman grave inscription +




^ permalink  raw  reply  [nested|flat] 4+ messages in thread


end of thread, other threads:[~2018-01-24 14:47 UTC | newest]

Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2017-11-27 14:04 minor annoyance - search_path not reset in/after dump/restore Frank van Vugt <ftm.van.vugt@foxi.nl>
2018-01-24 02:51 ` Bruce Momjian <bruce@momjian.us>
2018-01-24 03:45   ` David G. Johnston <david.g.johnston@gmail.com>
2018-01-24 14:47     ` Bruce Momjian <bruce@momjian.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