Commit Graph

376 Commits

Author SHA1 Message Date
Tom Lane 249724cb01 Create an ALTER DEFAULT PRIVILEGES command, which allows users to adjust
the privileges that will be applied to subsequently-created objects.

Such adjustments are always per owning role, and can be restricted to objects
created in particular schemas too.  A notable benefit is that users can
override the traditional default privilege settings, eg, the PUBLIC EXECUTE
privilege traditionally granted by default for functions.

Petr Jelinek
2009-10-05 19:24:49 +00:00
Tom Lane f033f6d28b Modify parallel pg_restore to track pending and ready items by means of
two new lists, rather than repeatedly rescanning the main TOC list.
This avoids a potential O(N^2) slowdown, although you'd need a *lot*
of tables to make that really significant; and it might simplify future
improvements in the scheduling algorithm by making the set of ready
items more easily inspectable.  The original thought that it would
in itself result in a more efficient job dispatch order doesn't seem
to have been borne out in testing, but it seems worth doing anyway.
2009-08-07 22:48:34 +00:00
Tom Lane b1732111f2 Fix pg_dump to do the right thing when escaping the contents of large objects.
The previous implementation got it right in most cases but failed in one:
if you pg_dump into an archive with standard_conforming_strings enabled, then
pg_restore to a script file (not directly to a database), the script will set
standard_conforming_strings = on but then emit large object data as
nonstandardly-escaped strings.

At the moment the code is made to emit hex-format bytea strings when dumping
to a script file.  We might want to change to old-style escaping for backwards
compatibility, but that would be slower and bulkier.  If we do, it's just a
matter of reimplementing appendByteaLiteral().

This has been broken for a long time, but given the lack of field complaints
I'm not going to worry about back-patching.
2009-08-04 21:56:09 +00:00
Tom Lane a5375bf903 Make pg_dump/pg_restore --clean options drop large objects too.
In passing, make invocations of lo_xxx functions a bit more schema-safe.

Itagaki Takahiro
2009-07-21 21:46:10 +00:00
Bruce Momjian d747140279 8.4 pgindent run, with new combined Linux/FreeBSD/MinGW typedef list
provided by Andrew.
2009-06-11 14:49:15 +00:00
Tom Lane 20d4005c30 Remove a couple of debugging messages that have been #ifdef'd out for ages.
Seems silly to ask translators to expend work on these, especially in
pluralized variants.
2009-06-04 19:16:48 +00:00
Andrew Dunstan f7a08e71e9 Fix logic to detect conflicts or blocks involving exclusive locks in parallel restore items.
If a currently running item needs an exclusive lock on any item that the candidate items needs
any sort of lock on, or vice versa, then the candidate item is not allowed to run now, and
must wait till later.
2009-04-12 21:02:44 +00:00
Peter Eisentraut 8032d76b5b Gettext plural support
In the backend, I changed only a handful of exemplary or important-looking
instances to make use of the plural support; there is probably more work
there.  For the rest of the source, this should cover all relevant cases.
2009-03-26 22:26:08 +00:00
Peter Eisentraut 249d936bed Rename pg_restore -m to -j, and add documentation about what good numbers
are.  per discussion on hackers
2009-03-20 09:21:09 +00:00
Tom Lane 0f80200a8e Fix identify_locking_dependencies to reflect the fact that fix_dependencies
previously repointed TABLE dependencies to TABLE DATA.  Mea culpa.
2009-03-13 22:50:44 +00:00
Andrew Dunstan c394bd331a Use thread-local storage for querybuffer in fmtId() on Windows, when needed (i.e. when
running pg_restore, which might run in parallel).
Only reopen archive file when we really need to read from it, in parallel code. Otherwise,
close it immediately in a worker, if possible.
2009-03-11 03:33:29 +00:00
Peter Eisentraut ff6c93bf51 Message tuning 2009-03-05 14:51:10 +00:00
Peter Eisentraut 9de59fd191 Add a -w/--no-password option that prevents all password prompts to all
programs that have a -W/--password option.

In passing, remove the ancient PSQL_ALWAYS_GET_PASSWORDS compile option.
2009-02-26 16:02:39 +00:00
Andrew Dunstan fae3083c3b Reconnect to the right database when using parallel restore with -C. Fixes bug reported by Olivier Prenant 2009-02-20 02:57:21 +00:00
Andrew Dunstan 775f1b379e Provide for parallel restoration from a custom format archive. Each data and
post-data step is run in a separate worker child (a thread on Windows, a child
process elsewhere) up to the concurrent number specified by the new pg_restore
command-line --multi-thread | -m switch.

Andrew Dunstan, with some editing by Tom Lane.
2009-02-02 20:07:37 +00:00
Magnus Hagander 3a819b0780 Throw an error when using -C and -1 at the same time in pg_restore.
It's not possible to do CREATE DATABASE inside a transaction, so previously
we just got a server error instead.

Backpatch to 8.2, which is where the -1 feature appeared.
2009-01-13 11:44:56 +00:00
Tom Lane b0a6ad70a1 Add a --role option to pg_dump, pg_dumpall, and pg_restore. This allows
performing dumps and restores in accordance with a security policy that
forbids logging in directly as superuser, but instead specifies that you
should log into an admin account and then SET ROLE to the superuser.

In passing, clean up some ugly and mostly-broken code for quoting shell
arguments in pg_dumpall.

Benedek László, with some help from Tom Lane
2009-01-05 16:54:37 +00:00
Peter Eisentraut cae565e503 SQL/MED catalog manipulation facilities
This doesn't do any remote or external things yet, but it gives modules
like plproxy and dblink a standardized and future-proof system for
managing their connection information.

Martin Pihlak and Peter Eisentraut
2008-12-19 16:25:19 +00:00
Bruce Momjian 2cdcf459ba Add comment about why pg_dump doesn't dump the public schema comment. 2008-09-05 23:53:42 +00:00
Andrew Dunstan 0ff74f03b1 add ; missing due to my carelessness 2008-05-04 08:32:21 +00:00
Andrew Dunstan c2c9fbef94 Place statement timeout more appropriately, per gripe from Tom. 2008-05-04 03:46:08 +00:00
Andrew Dunstan 17a56c0b55 Disable statement timeouts while making or restoring dumps.
Joshua Drake.
2008-05-03 23:32:32 +00:00
Tom Lane c22ed3d523 Turn the -i/--ignore-version options of pg_dump and pg_dumpall into no-ops:
the server version check is now always enforced.  Relax the version check to
allow a server that is of pg_dump's own major version but a later minor
version; this is the only case that -i was at all safe to use in.

pg_restore already enforced only a very weak version check, so this is
really just a documentation change for it.

Per discussion.
2008-04-13 03:49:22 +00:00
Tom Lane 68528d37bb Support a --no-tablespaces option in pg_dump/pg_dumpall/pg_restore, so that
dumps can be loaded into databases without the same tablespaces that the
source had.  The option acts by suppressing all "SET default_tablespace"
commands, and also CREATE TABLESPACE commands in pg_dumpall's case.

Gavin Roy, with documentation and minor fixes by me.
2008-03-20 17:36:58 +00:00
Tom Lane ea00ab8d64 Prevent pg_dump from dumping the comment (if any) on the 'public' schema.
This is to avoid uselessly requiring superuser permissions to restore
the dump without errors.  Pretty grotty, but no better alternative seems
available, at least not in the near term.
2008-01-14 19:27:41 +00:00
Tom Lane 229d406a9b Move resetting of currSchema to a spot where it's not vulnerable to getting
missed in possible future partial-drop scenarios.  Improve comment.
Per report from Zoltan Boszormenyi.
2007-11-24 20:26:49 +00:00
Bruce Momjian 7ebbc815d9 If pg_dump drops a schema, make sure 'search_path' it SET the next time
it is needed --- basically don't remember the previous 'search_path'
after a drop schema because it might have failed but be created later.
2007-11-24 17:45:32 +00:00
Bruce Momjian fdf5a5efb7 pgindent run for 8.3. 2007-11-15 21:14:46 +00:00
Tom Lane 27c033ed98 Make pg_dump and friends consistently report both the filename and the
errno string when complaining of fopen failures.  Per gripe from Bob
Pawley, it's not always instantly obvious to the user which name we
tried to open.
2007-10-28 21:55:52 +00:00
Tom Lane 8468146b03 Fix the inadvertent libpq ABI breakage discovered by Martin Pitt: the
renumbering of encoding IDs done between 8.2 and 8.3 turns out to break 8.2
initdb and psql if they are run with an 8.3beta1 libpq.so.  For the moment
we can rearrange the order of enum pg_enc to keep the same number for
everything except PG_JOHAB, which isn't a problem since there are no direct
references to it in the 8.2 programs anyway.  (This does force initdb
unfortunately.)

Going forward, we want to fix things so that encoding IDs can be changed
without an ABI break, and this commit includes the changes needed to allow
libpq's encoding IDs to be treated as fully independent of the backend's.
The main issue is that libpq clients should not include pg_wchar.h or
otherwise assume they know the specific values of libpq's encoding IDs,
since they might encounter version skew between pg_wchar.h and the libpq.so
they are using.  To fix, have libpq officially export functions needed for
encoding name<=>ID conversion and validity checking; it was doing this
anyway unofficially.

It's still the case that we can't renumber backend encoding IDs until the
next bump in libpq's major version number, since doing so will break the
8.2-era client programs.  However the code is now prepared to avoid this
type of problem in future.

Note that initdb is no longer a libpq client: we just pull in the two
source files we need directly.  The patch also fixes a few places that
were being sloppy about checking for an unrecognized encoding name.
2007-10-13 20:18:42 +00:00
Tom Lane 140d4ebcb4 Tsearch2 functionality migrates to core. The bulk of this work is by
Oleg Bartunov and Teodor Sigaev, but I did a lot of editorializing,
so anything that's broken is probably my fault.

Documentation is nonexistent as yet, but let's land the patch so we can
get some portability testing done.
2007-08-21 01:11:32 +00:00
Tom Lane fcb9535e8a Fix pg_restore to guard against unexpected EOF while reading an archive file.
Per report and partial patch from Chad Wagner.
2007-08-06 01:38:15 +00:00
Tom Lane 55a7cf80a0 Allow non-superuser database owners to create procedural languages.
A DBA is allowed to create a language in his database if it's marked
"tmpldbacreate" in pg_pltemplate.  The factory default is that this is set
for all standard trusted languages, but of course a superuser may adjust
the settings.  In service of this, add the long-foreseen owner column to
pg_language; renaming, dropping, and altering owner of a PL now follow
normal ownership rules instead of being superuser-only.
Jeremy Drake, with some editorialization by Tom Lane.
2007-03-26 16:58:41 +00:00
Neil Conway 7221b4fa50 Code cleanup: mark some variables with the "const" modifier, when they
are initialized with a string literal. Patch from Stefan Huehner.
2007-03-18 16:50:44 +00:00
Magnus Hagander 74096ed1fd Fix pg_dump on win32 to properly dump files larger than 2Gb when using
binary dump formats.
2007-02-19 15:05:06 +00:00
Bruce Momjian 8b4ff8b6a1 Wording cleanup for error messages. Also change can't -> cannot.
Standard English uses "may", "can", and "might" in different ways:

        may - permission, "You may borrow my rake."

        can - ability, "I can lift that log."

        might - possibility, "It might rain today."

Unfortunately, in conversational English, their use is often mixed, as
in, "You may use this variable to do X", when in fact, "can" is a better
choice.  Similarly, "It may crash" is better stated, "It might crash".
2007-02-01 19:10:30 +00:00
Bruce Momjian 6441288ec9 Add 'output file' option for pg_dumpall, especially useful for Win32,
where output redirection of child processes (pg_dump) doesn't work.

Dave Page
2007-01-25 03:30:43 +00:00
Tom Lane 379958128c Update pg_dump to support dumping operator families. 2007-01-23 17:54:50 +00:00
Tom Lane 5fc2d7e451 Suppress timezone (%Z) part of timestamp display when running on Windows,
because on that platform strftime produces localized zone names in varying
encodings.  Even though it's only in a comment, this can cause encoding
errors when reloading the dump script.  Per suggestion from Andreas
Seltenreich.  Also, suppress %Z on Windows in the %s escape of
log_line_prefix ... not sure why this one is different from the other two,
but it shouldn't be.
2006-11-21 22:19:46 +00:00
Tom Lane 1314983fd3 Code review for --no-data-for-failed-tables patch. Instead of trashing
one of the program's core data structures, make use of the existing
ability to selectively exclude TOC items by ID.  Slightly more code but
much less likely to create future maintenance problems.
2006-10-14 23:07:22 +00:00
Bruce Momjian f99a569a2e pgindent run for 8.2. 2006-10-04 00:30:14 +00:00
Bruce Momjian c61607bd52 Add pg_dump -X no-data-for-failed-tables option to suppress loading data
if table creation failed (the table already exists).

Martin Pitt
2006-08-01 18:21:44 +00:00
Bruce Momjian fcd1b0d891 Mark a few functions as static or NOT_USED. 2006-07-18 17:42:01 +00:00
Bruce Momjian e0522505bd Remove 576 references of include files that were not needed. 2006-07-14 14:52:27 +00:00
Bruce Momjian 399a36a75d Prepare code to be built by MSVC:
o  remove many WIN32_CLIENT_ONLY defines
	o  add WIN32_ONLY_COMPILER define
	o  add 3rd argument to open() for portability
	o  add include/port/win32_msvc directory for
	   system includes

Magnus Hagander
2006-06-07 22:24:46 +00:00
Tom Lane 134b463f02 Fix up pg_dump to do string escaping fully correctly for client encoding
and standard_conforming_strings; likewise for the other client programs
that need it.  As per previous discussion, a pg_dump dump now conforms
to the standard_conforming_strings setting of the source database.
We don't use E'' syntax in the dump, thereby improving portability of
the SQL.  I added a SET escape_strings_warning = off command to keep
the dumps from getting a lot of back-chatter from that.
2006-05-28 21:13:54 +00:00
Bruce Momjian 7a846ecc00 Use E'' strings internally only when standard_conforming_strings =
'off'. This allows pg_dump output with standard_conforming_strings =
'on' to generate proper strings that can be loaded into other databases
without the backslash doubling we typically do.  I have added the
dumping of the standard_conforming_strings value to pg_dump.

I also added standard backslash handling for plpgsql.
2006-05-26 23:48:54 +00:00
Tom Lane c76cb77105 Fix pg_restore to process BLOB COMMENT entries correctly; they aren't
really tables and shouldn't get DISABLE TRIGGER processing.  Per bug
#2452 from Robert Treat.
2006-05-24 21:20:11 +00:00
Peter Eisentraut 79e371037b Add strerror to pg_dump error messages where missing. 2006-05-22 11:21:54 +00:00
Tom Lane 3224f2ee25 Fix a couple of rather-pointless-but-easily-fixed Coverity warnings.
Per Martijn van Oosterhout.
2006-04-19 16:02:17 +00:00
Tom Lane 3ef151e0b7 Fix pg_restore -n option to do what the man page says it does. The
original coding only worked if one of the selTypes restriction options
was also given.  Per report from Nick Johnson.
2006-04-12 22:18:48 +00:00
Tom Lane 0ad14ebc8d Repair --single-transaction patch so it handles blobs correctly.
Simon Riggs
2006-02-14 23:30:43 +00:00
Tom Lane 1cf13e6f36 IMHO, --single-transaction should wrap *all* the commands in BEGIN/COMMIT,
not just some of them.
2006-02-13 21:30:19 +00:00
Bruce Momjian 58634caa0f Add MSVC support for utility commands and pg_dump.
Hiroshi Saito
2006-02-12 06:11:51 +00:00
Bruce Momjian 0f57851e31 Add psql option:
-1 or --single-transaction

Simon Riggs
2006-02-12 04:04:32 +00:00
Bruce Momjian 593763c086 This fixes pg_dump so that when using the '-O' no owners option it does
not print the owner name in the object comment.

eg:

--
-- Name: actor; Type: TABLE; Schema: public; Owner: chriskl; Tablespace:
--

Becomes:

--
-- Name: actor; Type: TABLE; Schema: public; Owner: -; Tablespace:
--

This makes it far easier to do 'user independent' dumps.  Especially for
distribution to third parties.

Christopher Kings-Lynne
2006-02-09 20:52:13 +00:00
Tom Lane 8e4057cc7d Fix pg_restore to properly discard COPY data when trying to continue
after an error in a COPY statement.  Formerly it thought the COPY data
was SQL commands, and got quite confused.

Stephen Frost
2006-02-05 20:58:47 +00:00
Bruce Momjian 4789e98801 Add GRANT ON SEQUENCE syntax to support sequence-only permissions.
Continue to support GRANT ON [TABLE] for sequences for backward
compatibility;  issue warning for invalid sequence permissions.

[Backward compatibility warning message.]

Add USAGE permission for sequences that allows only currval() and
nextval(), not setval().

Mention object name in grant/revoke warnings because of possible
multi-object operations.
2006-01-21 02:16:21 +00:00
Bruce Momjian 436a2956d8 Re-run pgindent, fixing a problem where comment lines after a blank
comment line where output as too long, and update typedefs for /lib
directory.  Also fix case where identifiers were used as variable names
in the backend, but as typedefs in ecpg (favor the backend for
indenting).

Backpatch to 8.1.X.
2005-11-22 18:17:34 +00:00
Bruce Momjian 1dc3498251 Standard pgindent run for 8.1. 2005-10-15 02:49:52 +00:00
Peter Eisentraut 1c25594549 Improve messages 2005-09-28 13:11:26 +00:00
Tom Lane e1a7d1b9f3 Avoid changing stdin/stdout to binary mode on Windows unless that is
really the source or destination of the archive.  I think this will
resolve recent complaints that password prompting is broken in pg_restore
on Windows.  Note that password prompting and reading from stdin is an
unworkable combination on Windows ... but that was true anyway.
2005-09-11 00:36:14 +00:00
Tom Lane 188c7c8ccf Add ALTER TABLE ENABLE/DISABLE TRIGGER commands. Change pg_dump to
use these instead of its previous hack of changing pg_class.reltriggers.
Documentation is lacking, will add that later.
Patch by Satoshi Nagayasu, review and some extra work by Tom Lane.
2005-08-23 22:40:47 +00:00
Tom Lane 83357da684 Cause ALTER INDEX OWNER to generate a warning and do nothing, rather than
erroring out as it has done for the last couple weeks.  Document that this
form is now ignored because indexes can't usefully have different owners
from their parent tables.  Fix pg_dump to not generate ALTER OWNER commands
for indexes.
2005-08-22 19:40:37 +00:00
Tom Lane 721e53785d Solve the problem of OID collisions by probing for duplicate OIDs
whenever we generate a new OID.  This prevents occasional duplicate-OID
errors that can otherwise occur once the OID counter has wrapped around.
Duplicate relfilenode values are also checked for when creating new
physical files.  Per my recent proposal.
2005-08-12 01:36:05 +00:00
Tom Lane 7a28de2052 pg_dump can now dump large objects even in plain-text output mode, by
using the recently added lo_create() function.  The restore logic in
pg_restore is greatly simplified as well, since there's no need anymore
to try to adjust database references to match a new set of blob OIDs.
2005-06-21 20:45:44 +00:00
Bruce Momjian ebc8649892 Since I needed this feature badly, I added the -n / --schema switch to
pg_restore. It restores the given schemaname only. It can be used in
conjunction with the -t and other switches to make the selection very
fine grained.

Richard van den Bergg, CISSP
2005-06-09 17:56:51 +00:00
Tom Lane f9ad8a2802 Guard against duplicate IDs in input file in SortTocFromFile().
Per report from Brian Hackett.
2005-05-17 17:30:29 +00:00
Neil Conway 47458f8c2f GCC 4.0 includes a new warning option, -Wformat-literal, that emits
a warning when a variable is used as a format string for printf()
and similar functions (if the variable is derived from untrusted
data, it could include unexpected formatting sequences). This
emits too many warnings to be enabled by default, but it does
flag a few dubious constructs in the Postgres tree. This patch
fixes up the obvious variants: functions that are passed a variable
format string but no additional arguments.

Most of these are harmless (e.g. the ruleutils stuff), but there
is at least one actual bug here: if you create a trigger named
"%sfoo", pg_dump will read uninitialized memory and fail to dump
the trigger correctly.
2005-04-30 08:08:51 +00:00
Tom Lane 348f856dc5 Revert addition of poorly-thought-out DUMP TIMESTAMP archive entry,
which induced bug #1597 in addition to having several other misbehaviors
(like labeling the dump with a completion time having nothing to do with
reality).  Instead just print out the desired strings where RestoreArchive
was already emitting the 'PostgreSQL database dump' and
'PostgreSQL database dump complete' strings.
2005-04-15 16:40:36 +00:00
Tom Lane 2e629080f7 Put 'dump complete' message in the right place, so it comes out where
it's supposed to when --file option is used.
2005-03-18 17:32:55 +00:00
Bruce Momjian 0542b1e2fe Use _() macro consistently rather than gettext(). Add translation
macros around strings that were missing them.
2005-02-22 04:43:23 +00:00
Tom Lane 9d58b9645e Make pg_dump and pg_restore handle binary archive formats correctly
when using stdout/stdin on Windows.
2005-01-26 19:44:43 +00:00
Tom Lane fd5437c78b Fix breakage created by addition of separate 'acl pass' in pg_dump.
Also clean up incredibly poor style in TocIDRequired() usage.
2005-01-25 22:44:31 +00:00
Tom Lane 3e2e58ba37 New routine _getObjectDescription() failed to cope with some aspects of
pre-7.3 pg_dump archive files: namespace isn't there, and in some cases
te->tag may already be quotified.  Per report from Alan Pevec and
followup testing.
2005-01-23 00:03:54 +00:00
Tom Lane 38498a28df Clean up pg_dump's handling of ownership for indexes (including
pkey/unique constraint indexes) and schemas.  Per report from
Michael Fuhr.
2005-01-11 05:14:13 +00:00
Tom Lane 04baa0ebf9 Update pg_dump to use SET DEFAULT_TABLESPACE instead of explicit
tablespace clauses; this should improve compatibility of dump files.
Philip Warner, some rework by Tom Lane.
2004-11-06 19:36:02 +00:00
Peter Eisentraut 77c0204a37 Message styling 2004-10-22 16:04:35 +00:00
Tom Lane 07ccbeb360 Include schema name in pg_restore -l output, per request from Phil Endecott. 2004-10-08 15:03:26 +00:00
Tom Lane 1d681d6cee Fix some problems with restoring databases owned by non-superusers,
as per bug #1249; and remove the last vestiges of using \connect to
change authorization.
2004-09-10 20:05:18 +00:00
Tom Lane c7040429e7 Fix obviously-utterly-untested noTocComments code. 2004-08-30 19:44:14 +00:00
Bruce Momjian b6b71b85bc Pgindent run for 8.0. 2004-08-29 05:07:03 +00:00
Bruce Momjian f7168bd44c They are two different problems; the TOC entry is important for any
multiline command  or to rerun the command easily later.

Whereas displaying the failed SQL command is a matter of fixing the
error
messages.

The latter is complicated by failed COPY commands which, with
die-on-errors
off, results in the data being processed as a command, so dumping the
command will dump all of the data.

In the case of long commands, should the whole command be dumped? eg.
(eg.
several pages of function definition).

In the case of the COPY command, I'm not sure what to do. Obviously, it
would be best to avoid sending the data, but the data and command are
combined (from memory). Also, the 'data' may be in the form of INSERT
statements.

Attached patch produces the first 125 chars of the command:

pg_restore: [archiver (db)] Error while PROCESSING TOC:
pg_restore: [archiver (db)] Error from TOC Entry 26; 1255 16449270
FUNCTION
plpgsql_call_handler() pjw
pg_restore: [archiver (db)] could not execute query: ERROR:  function
"plpgsql_call_handler" already exists with same argument types
     Command was: CREATE FUNCTION plpgsql_call_handler() RETURNS
language_handler
     AS '/var/lib/pgsql-8.0b1/lib/plpgsql', 'plpgsql_call_han...
pg_restore: [archiver (db)] Error from TOC Entry 27; 1255 16449271
FUNCTION
plpgsql_validator(oid) pjw
pg_restore: [archiver (db)] could not execute query: ERROR:  function
"plpgsql_validator" already exists with same argument types
     Command was: CREATE FUNCTION plpgsql_validator(oid) RETURNS void
     AS '/var/lib/pgsql-8.0b1/lib/plpgsql', 'plpgsql_validator'
     LANGU...

Philip Warner
2004-08-20 20:00:34 +00:00
Bruce Momjian daa076c4fd > Please find attached a submission to add a "exit on error" option to
> pg_restore, as it seems that some people have scripts that rely on the
> previous "abort on error" default behavior when restoring data with a
> direct connection.
>
> Fabien Coelho
2004-08-20 04:20:23 +00:00
Tom Lane 2193121fa9 Fix breakage with PUBLIC schema. Try to untwist the remarkably contorted
logic a little bit.
2004-08-13 21:37:28 +00:00
Tom Lane 576856b698 Dump comments on columns of composite types.
Instead of putting all the OWNER TO commands at the end, it dumps then
after each object.  This is WAY more readable and nice.  ACLs are still
at the end.

Christopher Kings-Lynne
2004-08-04 17:13:03 +00:00
Bruce Momjian 45995219a0 Here is another patch that fixes a stack of pg_dump bugs:
* Fix help text ordering

* Add back --set-session-authorization to pg_dumpall.  Updated the docs
for that.  Updated help for that.

* Dump ALTER USER commands for the cluster owner ("pgsql").  These are
dumped AFTER the create user and create database commands in case the
permissions to do these have been revoked.

* Dump ALTER OWNER for public schema (because it's possible to change
it).  This was done by adding TOC entries for the public schema, and
filtering them out at archiver time.  I also save the owner in the TOC
entry just for the public schema.

* Suppress dumping single quotes around schema_path and DateStyle
options when they are set using ALTER USER or ALTER DATABASE.  Added a
comment to the steps in guc.c to remind people to update that list.

* Fix dumping in --clean mode against a pre-7.3 server.  It just sets
all drop statements to assume the public schema, allowing it to restore
without error.

* Cleaned up text output.  eg. Don't output -- Tablespaces comment if
there are none.  Same for groups and users.

* Make the commands to DELETE FROM pg_shadow and DELETE FROM pg_group
only be output when -c mode is enabled.  I'm not sure why that hasn't
been done before?!?!

This should be good for application asap, after which I will start on
regression dumping 7.0-7.4 databases.

Christopher Kings-Lynne
2004-07-19 21:39:48 +00:00
Tom Lane 465edca3ec Fix incorrect tracking of session authorization in the presence of ACLs
that contain rights granted by non-owners.  Per bug report from
Nishad Prakash.
2004-07-19 21:02:17 +00:00
Bruce Momjian dc0e76ca36 Change pg_dump to use ALTER OWNER commands instead of SET SESSION
AUTHORIZATION commands by default.  Move all GRANT and REVOKE commands
to the end of the dump to avoid restore failures in several situations.
Bring back --use-set-session-authorization option to get previous SET
behaviour

Christopher Kings-Lyne
2004-07-13 03:00:17 +00:00
Bruce Momjian bef228d1ee Add end-of-dump markers for pg_dump and pg_dumpall. 2004-05-19 21:21:26 +00:00
Bruce Momjian ec7c4c1b66 Please find attached a small patch so that "pg_restore" ignores some sql
errors. This is the second submission, which integrates Tom comments about
localisation and exit code. I also added some comments about one sql
command which is not ignored.

Fabien COELHO
2004-04-22 02:39:10 +00:00
Bruce Momjian f23cce73b3 Use the new GUC variable default_with_oids in pg_dump, rather than using
WITH/WITHOUT OIDS in dump files.  This makes dump files more portable.

I have updated the pg_dump version so old binary dumps will load fine.

Pre-7.5 dumps use WITHOUT OIDS in SQL were needed, so they should be
fine.
2004-03-24 03:06:08 +00:00
Tom Lane 9e733eab69 Modify pg_dump so that the preferred dump order is by name within
object types, rather than by OID.  This should help ensure consistent
dump output from databases that are logically the same but have different
histories, per recent discussion about 'diffing' databases.  The patch
is bulky because of renaming of fields, but not very complicated.
Also, do some tweaking to cause BLOB restoration to be done in a better
order, and clean up pg_restore's textual output to exactly match pg_dump.
2004-03-03 21:28:55 +00:00
Tom Lane 92bec9a0bc Cause pg_dump to emit a 'SET client_encoding' command at the start of
any restore operation, thereby ensuring that dumped data is interpreted
the same way it was dumped even if the target database has a different
encoding.  Per suggestions from Pavel Stehule and others.  Also,
simplify scheme for handling check_function_bodies ... we may as well
just set that at the head of the script.
2004-02-24 03:35:19 +00:00
Tom Lane 9a4ef0c562 Fix ReadOffset() to work correctly when off_t is wider than int. 2004-01-04 04:02:15 +00:00
Tom Lane 005a1217fb Massive overhaul of pg_dump: make use of dependency information from
pg_depend to determine a safe dump order.  Defaults and check constraints
can be emitted either as part of a table or domain definition, or
separately if that's needed to break a dependency loop.  Lots of old
half-baked code for controlling dump order removed.
2003-12-06 03:00:16 +00:00
PostgreSQL Daemon 969685ad44 $Header: -> $PostgreSQL Changes ... 2003-11-29 19:52:15 +00:00
Tom Lane 3b64171edb Complain if pg_restore is given both -d and -f options; this suggests
the user is confused about whether -f is input or output file.
2003-10-20 21:05:12 +00:00
Tom Lane ef88199f61 Issue 'SET check_function_bodies = false' to suppress possible restore
failures in SQL functions, due to forward references or unqualified
references to objects in other schemas.  Per recent discussion.
2003-10-03 20:10:59 +00:00
Tom Lane a9e9abebd9 Issue CREATE SCHEMA as the originally connecting user, with an
AUTHORIZATION clause to specify the desired owner.  This allows a
superuser to restore schemas owned by users without CREATE-SCHEMA
permissions (ie, schemas originally created by a superuser using
AUTHORIZATION).  --no-owner can be specified to suppress the
AUTHORIZATION clause if need be.
2003-09-23 23:31:52 +00:00
Tom Lane 6767cebc6f pg_dump/pg_restore now always use SET SESSION AUTHORIZATION, not \connect,
to control object ownership.  The use-set-session-authorization and
no-reconnect switches are obsolete (still accepted on the command line,
but they don't do anything).  This is a precursor to fixing handling
of CREATE SCHEMA, which will be a separate commit.
2003-09-23 22:48:53 +00:00
Tom Lane 209a8d63df pg_dump and pg_restore -r had managed to diverge on the ordering of
different object types.  Fix, and centralize logic to try to prevent
the same mistake in future.
2003-08-28 20:21:34 +00:00
Bruce Momjian 089003fb46 pgindent run. 2003-08-04 00:43:34 +00:00
Peter Eisentraut c154fc3a20 Apply message style guide to frontend programs. 2003-07-23 08:47:41 +00:00
Tom Lane f85f43dfb5 Backend support for autocommit removed, per recent discussions. The
only remnant of this failed experiment is that the server will take
SET AUTOCOMMIT TO ON.  Still TODO: provide some client-side autocommit
logic in libpq.
2003-05-14 03:26:03 +00:00
Tom Lane 228697179a Fix erroneous space calculation leading to core dump in dumpProcLangs,
per report from Olivier Prenant.  Also fix off-by-one space calculation
in ReadToc; this woould not have hurt us until we had more than 100
dependencies for a single object, but wrong is wrong.
2003-05-03 22:18:59 +00:00
Tom Lane e4704001ea This patch fixes a bunch of spelling mistakes in comments throughout the
PostgreSQL source code.

Neil Conway
2003-03-10 22:28:22 +00:00
Tom Lane b9e8ffcd5d pg_restore failed to restore blobs if -X disable-triggers is specified. 2003-03-09 19:38:52 +00:00
Bruce Momjian 3f6333357f Make pg_dump/restore safer for autocommit=off in postgresql.conf. 2003-02-14 19:40:42 +00:00
Tom Lane e0a1ee2053 Cleaner solution to the problem of loading pre-7.3 dumps containing
columns of type lo (see contrib/lo).  Rather than hacking the function
definitions on-the-fly, just modify the queries issued by FixupBlobRefs
so that they work even if CREATE CAST hasn't been issued.
2003-02-01 22:06:59 +00:00
Tom Lane 4b833d080b Prevent core dump when die_horribly() is called with null AH pointer.
Problem reported and fixed by Oliver Elphick.
2003-01-27 00:23:38 +00:00
Hiroshi Inoue de432ce39e Change Adjust_lo_type() so that it doesn't cause an error
even when cast functions are allowed to be volatile.
2003-01-13 04:28:55 +00:00
Hiroshi Inoue 150ffb2d50 Adjust lo type in contrib during pg_restore so that pg_restore could
reload the type.
2003-01-03 18:05:02 +00:00
Bruce Momjian 1b7f3cc02d This patch implements FOR EACH STATEMENT triggers, per my email to
-hackers a couple days ago.

Notes/caveats:

        - added regression tests for the new functionality, all
          regression tests pass on my machine

        - added pg_dump support

        - updated PL/PgSQL to support per-statement triggers; didn't
          look at the other procedural languages.

        - there's (even) more code duplication in trigger.c than there
          was previously. Any suggestions on how to refactor the
          ExecXXXTriggers() functions to reuse more code would be
          welcome -- I took a brief look at it, but couldn't see an
          easy way to do it (there are several subtly-different
          versions of the code in question)

        - updated the documentation. I also took the liberty of
          removing a big chunk of duplicated syntax documentation in
          the Programmer's Guide on triggers, and moving that
          information to the CREATE TRIGGER reference page.

        - I also included some spelling fixes and similar small
          cleanups I noticed while making the changes. If you'd like
          me to split those into a separate patch, let me know.

Neil Conway
2002-11-23 03:59:09 +00:00
Tom Lane 7a0671a37c Suppress compile warnings on OS X. 2002-10-27 02:52:10 +00:00
Bruce Momjian 3fd6d3260f Change to fseeko(), per Philip. 2002-10-25 03:47:30 +00:00
Bruce Momjian fc5c577e34 Allow fseeko in pg_dump only if fseeko() will work for all supported file
sizes.
2002-10-25 01:33:17 +00:00
Bruce Momjian 2b287020f4 Allow 8-byte off_t to properly pg_dump, from Philip Warner with mods by Bruce. 2002-10-22 19:15:23 +00:00
Bruce Momjian cda776e613 Make pg_dump save for autocommit = off. 2002-10-16 05:46:54 +00:00
Bruce Momjian e50f52a074 pgindent run. 2002-09-04 20:31:48 +00:00
Peter Eisentraut 7af5ea736f Reimplement pg_dumpall in C. Currently no change in functionality,
except that it's more robust, reconnects less often, and is NLS'ed.
2002-08-27 18:57:26 +00:00
Peter Eisentraut 6faf8024fa Enable large file support.
Use off_t and size_t in pg_dump to handle file offset arithmetic correctly.
2002-08-20 17:54:45 +00:00
Peter Eisentraut c828ec8820 Make pg_dump output more portable and more pleasing to look at.
The -n and -N options were removed.  Quoting is now smart enough to
supply quotes if and only if necessary.

Numerical types are now printed without quotes, except in cases of
special values such as NaN.

Boolean values printed as true and false.

Most string literals now do not escape whitespace characters (newlines,
etc.) for portability.

SET SESSION AUTHORIZATION argument is a string literal, to follow SQL.

Made commands output by pg_dump use consistent spacing and indentation.
2002-08-18 09:36:26 +00:00
Peter Eisentraut 029aa97f2d Make sure all clients have the same understanding of default user name
and database.  In particular, make script wrappers understand the
PGDATABASE environment variable.
2002-08-10 16:57:32 +00:00
Bruce Momjian d59478c4f3 More clearly document in pg_dump when we are dealing with an object name
as it appears in the schema dump, and index tags.
2002-07-04 15:35:07 +00:00
Bruce Momjian 3722dee6d9 Document function args are required for pg_restore -P.
Fix pg_dump to not quote the function name in the storage tag.
Fix pg_dump so GRANT/REVOKE(ACL) tag entries are not quoted, for
	consistency.
Fix pg_restore to properly handle quotes and some spaces in -P.
2002-07-04 03:04:55 +00:00
Bruce Momjian f4590995c9 The attached patch fixes 2 memory leaks in pg_dump, as well as corrects
a spelling mistake and deletes an antiquated comment.

Neil Conway
2002-07-02 05:49:52 +00:00
Tom Lane 9ca89b4f8c Another place that needs schema qualification. 2002-05-29 01:49:57 +00:00
Tom Lane 49bf04ba8c Fix some more not-schema-aware queries in pg_dump. Also fix some places
that would do the wrong thing with BLOB OIDs exceeding 2G.
2002-05-29 01:38:56 +00:00
Tom Lane 36a1e732a6 Rework pg_dump namespace search criteria so that dumping of user objects
having names conflicting with system objects will work --- the search
path is now user-schema, pg_catalog rather than implicitly the other way
around.  Note this requires being careful to explicitly qualify references
to system names whenever pg_catalog is not first in the search path.
Also, add support for dumping ACLs of schemas.
2002-05-28 22:26:57 +00:00
Tom Lane 9f0ae0c820 First pass at schema-fying pg_dump/pg_restore. Much to do still,
but the basic capability seems to work.
2002-05-10 22:36:27 +00:00
Tom Lane 340b66cc70 Cause fmtId to always use its internal buffer for the returned value,
in hopes of making erroneous usage more apparent.  Per discussion 15-Apr.
2002-05-06 17:34:45 +00:00
Bruce Momjian 8be68479dc Remove compile warnings for lo dump by casting to char *. 2002-04-24 14:03:22 +00:00
Bruce Momjian e975123454 Speed improvement for large object restore.
Mario Weilguni
2002-04-24 02:21:04 +00:00
Tom Lane 15c30b6f9a Be more wary about mixed-case database names and user names. Get
the CREATE DATABASE command right in pg_dump -C case.
2002-02-11 00:18:20 +00:00
Tom Lane 6a67d9def0 Fix failure to reconnect as sequence's owner before issuing setval(). 2002-02-06 17:27:50 +00:00
Bruce Momjian 69f909ba10 You might want to run pg_indent on pg_backup_db.c however ...
tom lane
2002-01-18 19:17:05 +00:00
Tom Lane bb698c25c7 Fix pg_restore to handle the 'set max oid' entry correctly in archives
dumped by pg_dump -o.  Per bug report posted by Bruce; fix is from
Philip Warner, reviewed by Tom Lane.
2002-01-18 17:13:51 +00:00
Tom Lane 64af43a15f Add casts to suppress compiler warnings observed on Darwin platform
(surprised no one has reported these yet...)
2001-11-08 04:05:13 +00:00
Bruce Momjian ea08e6cd55 New pgindent run with fixes suggested by Tom. Patch manually reviewed,
initdb/regression tests pass.
2001-11-05 17:46:40 +00:00
Philip Warner 1ef62bb6fc - Fix compiler warning in pg_restore
- Fix handling of {data/schema}-only restores when using a full
  backup file; prior version was restoring schema in data-only
  restores. Added enum to make code easier to understand.
2001-11-04 04:05:36 +00:00
Bruce Momjian b81844b173 pgindent run on all C files. Java run to follow. initdb/regression
tests pass.
2001-10-25 05:50:21 +00:00
Tom Lane b662e321c5 Forbid the switch combination --clean --create, which is pointless
(why bother dropping individual objects in a just-created database?)
as well as dangerous (as the code stands, the drops will be issued in
the wrong database, namely the one you were originally connected to).
2001-10-23 21:26:44 +00:00
Peter Eisentraut fdf07fe14f For consistency with the rest of PostgreSQL, rename BLOBs to large objects
in messages and documentation.
2001-09-21 21:58:30 +00:00
Peter Eisentraut 627c0d4472 Add option to output SET SESSION AUTHORIZATION commands rather than
\connect, to avoid possible password prompts and such, at the drawback of
having to have superuser access.
2001-08-22 20:23:24 +00:00
Peter Eisentraut 30c975e2cb One more round of translations and slight message tweaks 2001-08-19 22:17:03 +00:00
Peter Eisentraut a0c449a0f8 Make pg_dump handle the new privileges.
Don't hardcode the maximum accepted server version, use PG_VERSION instead.
Install a notice processor so notices are handled like error messages.
Word smithing.
2001-08-12 19:02:39 +00:00
Peter Eisentraut 30ab5bd43d More message munging and localization for pg_dump, especially the
--verbose messages, which had not been considered so far.  Output to the
terminal should okay now; comments written into the dump are still English
only, which may or may not be the desirable thing.
2001-07-03 20:21:50 +00:00
Peter Eisentraut b559382134 National language support for pg_dump and pg_restore. Combined with big
message clean up.
2001-06-27 21:21:37 +00:00
Peter Eisentraut f000ffd28e Add -U and -W options to pg_dump and friends to support non-interactive
specification of username (like in psql).  pg_dumpall now works with
password authentication.
2001-05-17 21:12:49 +00:00
Philip Warner bb30d49a2a - Don't dump COMMENTs in data-only dumps
- Fix view dumping SQL for V7.0
 - Fix bug when getting view oid with long view names
 - Treat SEQUENCE SET TOC entries as data entries rather than schema
   entries.
 - Make allowance for data entries that did not have a data dumper
   routine (eg. SEQUENCE SET)
2001-05-12 01:03:59 +00:00
Philip Warner 8dc42a3aa2 - Fixed CONSTRAINT TRIGGER dump to record tgconstrelid properly
- pgsql v7.0 compatbility
2001-04-25 07:03:20 +00:00
Philip Warner 232d8fa3c4 - Get view OID based on rule OID not base table OID
- Fix crash due to null string pointer in some tar files with some libs
2001-04-14 13:11:03 +00:00
Philip Warner 135040d511 Patch to put rudimentary dependency support into pg_dump. This addresses
the UDT/function order problem.

    - Rudimentary support for dependencies in archives.
      Uses dependencies to modify the OID used in sorting TOC
      entries. This will NOT handle multi-level dependencies,
      but will manage simple relationships like UDTs & their functions.

    - Treat OIDs with more respect (avoid using ints, use macros
      for conversion & comparison).
2001-04-01 05:42:51 +00:00
Bruce Momjian 9e1552607a pgindent run. Make it all clean. 2001-03-22 04:01:46 +00:00
Philip Warner cfeccdf80a - Added CVS headers to files
- Avoid forcing table name to lower case in FixupBlobXrefs
 - Removed fmtId calls for all ArchiveEntry name fields. This fixes
   quoting problems in trigger enable/disable code for mixed case
   table names, and avoids commands like 'pg_restore -t '"TblA"'
2001-03-19 02:35:29 +00:00
Philip Warner 5c1b00450c Fixed but in _enableTriggersIfNecessary introduced by previous patches by me
which caused segfault in a data-only retore with BLOBs
2001-03-18 03:45:12 +00:00
Philip Warner ccca223b5c - Use subselect when enabling triggers,
- Use exact table names when enabling/disabling triggers
2001-03-13 13:18:44 +00:00
Philip Warner aa28eebf4c - Only disable triggers in DataOnly (or implied data-only) restores.
- Change -U option to -L to allow -U to specify username in future. (pg_restore)
2001-03-06 04:08:04 +00:00
Tom Lane 2b0f8ae009 Fix pg_dump crashes caused by bogus use of va_start/va_end (only seen
on some platforms, which is not too surprising considering how platform
specific these macros must be).
2001-02-23 22:52:32 +00:00
Bruce Momjian 51cd037746 The following patch is required for successful compilation on Irix.
Robert E. Bruccole
2001-01-29 00:11:41 +00:00
Philip Warner 7fcd675dc3 When dropping the schema, reconnect as owner of each object. 2001-01-27 12:35:29 +00:00
Philip Warner 06ef1ef2ec - Check ntuples == 1 for various SELECT statements.
- Fix handling of --tables=* (multiple tables never worked properly, AFAICT)
- strdup() the current user in DB routines
- Check results of IO routines more carefully.
- Check results of PQ routines more carefully.

Have not fixed index output yet.
2001-01-12 04:32:07 +00:00
Tom Lane 5cf81b3c06 Silence compiler warning. 2000-12-07 02:52:27 +00:00
Bruce Momjian ebd61ac03f Remove -k unix socketpath option from client side, allow hostname with
leading slash to behave as a unix socket path.
2000-11-13 23:37:54 +00:00
Bruce Momjian 2150c2edf1 UUNET is looking into offering PostgreSQL as a part of a managed web
hosting product, on both shared and dedicated machines.  We currently
offer Oracle and MySQL, and it would be a nice middle-ground.
However, as shipped, PostgreSQL lacks the following features we need
that MySQL has:

1. The ability to listen only on a particular IP address.  Each
   hosting customer has their own IP address, on which all of their
   servers (http, ftp, real media, etc.) run.
2. The ability to place the Unix-domain socket in a mode 700 directory.
   This allows us to automatically create an empty database, with an
   empty DBA password, for new or upgrading customers without having
   to interactively set a DBA password and communicate it to (or from)
   the customer.  This in turn cuts down our install and upgrade times.
3. The ability to connect to the Unix-domain socket from within a
   change-rooted environment.  We run CGI programs chrooted to the
   user's home directory, which is another reason why we need to be
   able to specify where the Unix-domain socket is, instead of /tmp.
4. The ability to, if run as root, open a pid file in /var/run as
   root, and then setuid to the desired user.  (mysqld -u can almost
   do this; I had to patch it, too).

The patch below fixes problem 1-3.  I plan to address #4, also, but
haven't done so yet.  These diffs are big enough that they should give
the PG development team something to think about in the meantime :-)
Also, I'm about to leave for 2 weeks' vacation, so I thought I'd get
out what I have, which works (for the problems it tackles), now.

With these changes, we can set up and run PostgreSQL with scripts the
same way we can with apache or proftpd or mysql.

In summary, this patch makes the following enhancements:

1. Adds an environment variable PGUNIXSOCKET, analogous to MYSQL_UNIX_PORT,
   and command line options -k --unix-socket to the relevant programs.
2. Adds a -h option to postmaster to set the hostname or IP address to
   listen on instead of the default INADDR_ANY.
3. Extends some library interfaces to support the above.
4. Fixes a few memory leaks in PQconnectdb().

The default behavior is unchanged from stock 7.0.2; if you don't use
any of these new features, they don't change the operation.

David J. MacKenzie
2000-11-13 15:18:15 +00:00
Philip Warner 44954fae08 Added long-standing transaction when restoring BLOBS (uses commit every BLOB_BATCH_SIZE)
Prevent dumping of languages from template1.
2000-10-31 14:20:30 +00:00
Philip Warner 3cf6e94844 Use new datlastsysoid field in pg_database + some cleanups & fixes 2000-10-22 18:13:09 +00:00
Philip Warner 1b1dbb861d Fix bug in sequence dumping using new setval function 2000-10-13 00:43:31 +00:00
Philip Warner c2e302071f - Only disable triggers for the table being loaded
- disable triggers prior to BLOB load
- better query for loading blob xrefs
- Fixes to error handling code
2000-08-05 09:57:46 +00:00
Philip Warner 92bd532c1e - Added --create, --no-owner, --superuser, --no-reconnect (pg_dump & pg_restore)
- Added code to dump 'Create Schema' statement (pg_dump)
- Don't bother to disable/enable triggers if we don't have a superuser (pg_restore)
- Cleaned up code for reconnecting to database.
- Force a reconnect as superuser before enabling/disabling triggers.
- Added & Removed --throttle (pg_dump)
- Fixed minor bug in language dumping code: expbuffres were not being reset.
- Fixed version number initialization in _allocAH (pg_backup_archiver.c)
- Added second connection when restoring BLOBs to allow temp. table to survive
  (db reconnection causes temp tables to be lost).
2000-08-01 15:51:45 +00:00
Bruce Momjian 56c754a555 Some pedantic compile syntax errors to fix with the following patch
for today's snapshot

Andreas
2000-07-27 19:49:24 +00:00
Philip Warner bb080400f8 - no longer put ACLs at end of dump
- connect as appropriate user in pg_restore with db connection
- dump owner of rule in pg_dump
2000-07-24 06:24:26 +00:00
Philip Warner e8f69be054 - Support for BLOB output from pg_dump and input via pg_restore
- Support for direct DB connection in pg_restore
- Fixes in support for --insert flag
- pg_dump now outputs in modified OID order
- various other bug fixes
2000-07-21 11:40:08 +00:00
Jan Wieck 43f6ab8654 Please find attached a patch for the pg_dump directory which addresses:
- The problems Jan reported

- incompatibility with configure (now uses HAVE_LIBZ instead of HAVE_ZLIB)

- a problem in auto-detecting archive file format on piped archives

Philip Warner
2000-07-06 18:39:39 +00:00
Bruce Momjian 500b62b057 pg_dump patch from Philip Warner 2000-07-04 14:25:28 +00:00