summaryrefslogtreecommitdiff
path: root/src/bin
Commit message (Collapse)AuthorAgeFilesLines
* Tab completion for event triggers.Robert Haas2014-04-141-3/+85
| | | | Ian Barwick
* Create infrastructure for moving-aggregate optimization.Tom Lane2014-04-121-0/+68
| | | | | | | | | | | | | | | | | | | Until now, when executing an aggregate function as a window function within a window with moving frame start (that is, any frame start mode except UNBOUNDED PRECEDING), we had to recalculate the aggregate from scratch each time the frame head moved. This patch allows an aggregate definition to include an alternate "moving aggregate" implementation that includes an inverse transition function for removing rows from the aggregate's running state. As long as this can be done successfully, runtime is proportional to the total number of input rows, rather than to the number of input rows times the average frame length. This commit includes the core infrastructure, documentation, and regression tests using user-defined aggregates. Follow-on commits will update some of the built-in aggregates to use this feature. David Rowley and Florian Pflug, reviewed by Dean Rasheed; additional hacking by me
* Allow "-C variable" and "--describe-config" even to root users.Tom Lane2014-04-041-3/+5
| | | | | | | | | | | | | | | | | | | | | | | | There's no really compelling reason to refuse to do these read-only, non-server-starting options as root, and there's at least one good reason to allow -C: pg_ctl uses -C to find out the true data directory location when pointed at a config-only directory. On Windows, this is done before dropping administrator privileges, which means that pg_ctl fails for administrators if and only if a config-only layout is used. Since the root-privilege check is done so early in startup, it's a bit awkward to check for these switches. Make the somewhat arbitrary decision that we'll only skip the root check if -C is the first switch. This is not just to make the code a bit simpler: it also guarantees that we can't misinterpret a --boot mode switch. (While AuxiliaryProcessMain doesn't currently recognize any such switch, it might have one in the future.) This is no particular problem for pg_ctl, and since the whole behavior is undocumented anyhow, it's not a documentation issue either. (--describe-config only works as the first switch anyway, so this is no restriction for that case either.) Back-patch to 9.2 where pg_ctl first began to use -C. MauMau, heavily edited by me
* Make sure -D is an absolute path when starting server on Windows.Tom Lane2014-04-041-1/+13
| | | | | | | | | | | | | This is needed because Windows services may get started with a different current directory than where pg_ctl is executed. We want relative -D paths to be interpreted relative to pg_ctl's CWD, similarly to what happens on other platforms. In support of this, move the backend's make_absolute_path() function into src/port/path.c (where it probably should have been long since) and get rid of the rather inferior version in pg_regress. Kumar Rajeev Rastogi, reviewed by MauMau
* Fix some compiler warnings that clang emits with -pedantic.Robert Haas2014-04-042-6/+9
| | | | Andres Freund
* psql: display "Replica Identity" only for FULL and NOTHINGBruce Momjian2014-03-291-3/+6
| | | | | INDEX is already displayed on the index, and we now exclude pg_catalog. DEFAULT is not displayed.
* Fix dumping of a materialized view that depends on a table's primary key.Tom Lane2014-03-293-7/+67
| | | | | | | | | | | | | | | | | | It is possible for a view or materialized view to depend on a table's primary key, if the view query relies on functional dependency to abbreviate a GROUP BY list. This is problematic for pg_dump since we ordinarily want to dump view definitions in the pre-data section but indexes in post-data. pg_dump knows how to deal with this situation for regular views, by breaking the view's ON SELECT rule apart from the view proper. But it had not been taught what to do about materialized views, and in fact mistakenly dumped them as regular views in such cases, as seen in bug #9616 from Jesse Denardo. If we had CREATE OR REPLACE MATERIALIZED VIEW, we could fix this in a manner analogous to what's done for regular views; but we don't yet, and we'd not back-patch such a thing into 9.3 anyway. As a hopefully- temporary workaround, break the circularity by postponing the matview into post-data altogether when this case occurs.
* psql: update "replica identity" display for \d+Bruce Momjian2014-03-261-3/+8
| | | | | | Display "replica identity" only for \d plus mode, exclude system schema objects, and display all possible values, not just non-default, non-index ones.
* Remove MinGW readdir/errno bug workaround fixed on 2003-10-10Bruce Momjian2014-03-214-36/+0
|
* Properly check for readdir/closedir() failuresBruce Momjian2014-03-214-36/+72
| | | | | | | Clear errno before calling readdir() and handle old MinGW errno bug while adding full test coverage for readdir/closedir failures. Backpatch through 8.4.
* Some minor improvements to logical decoding document.Fujii Masao2014-03-191-1/+1
| | | | Also improve help message in pg_recvlogical.
* Fix misc typos in comments.Heikki Linnakangas2014-03-181-3/+3
|
* Fix uninitialized variable.Robert Haas2014-03-181-1/+1
| | | | Report from Andres Freund, but not his fix.
* Add pg_recvlogical, a tool to receive data logical decoding data.Robert Haas2014-03-188-125/+1135
| | | | | | | This is fairly basic at the moment, but it's at least useful for testing and debugging, and possibly more. Andres Freund
* Fix pg_dumpall option parsing: -i doesn't take an argument.Tom Lane2014-03-181-1/+1
| | | | | | This used to work properly, but got fat-fingered in commit 3dee636e0404885d07885d41c0d70e50c784f324. Per bug #9620 from Nicolas Payart.
* Fix help message and document in pg_receivexlog.Fujii Masao2014-03-181-1/+1
| | | | | Add SLOTNAME placeholder to --slot option in help message and document.
* Allow psql to print COPY command status in more cases.Tom Lane2014-03-133-29/+53
| | | | | | | | | | | | | | Previously, psql would print the "COPY nnn" command status only for COPY commands executed server-side. Now it will print that for frontend copies too (including \copy). However, we continue to suppress the command status for COPY TO STDOUT, since in that case the copy data has been routed to the same place that the command status would go, and there is a risk of the status line being mistaken for another line of COPY data. Doing that would break existing scripts, and it doesn't seem worth the benefit --- this case seems fairly analogous to SELECT, for which we also suppress the command status. Kumar Rajeev Rastogi, with substantial review by Amit Khandekar
* C comments: remove odd blank lines after #ifdef WIN32 linesBruce Momjian2014-03-132-4/+3
| | | | A few more
* C comments: remove odd blank lines after #ifdef WIN32 linesBruce Momjian2014-03-131-1/+0
|
* Fix tracking of psql script line numbers during \copy from another place.Tom Lane2014-03-104-14/+25
| | | | | | | | | | | | | | | | | | | | | | | Commit 08146775acd8bfe0fcc509c71857abb928697171 changed do_copy() to temporarily scribble on pset.cur_cmd_source. That was a mighty ugly bit of code in any case, but in particular it broke handleCopyIn's ability to tell whether it was reading from the current script source file (in which case pset.lineno should be incremented for each line of COPY data), or from someplace else (in which case it shouldn't). The former case still worked, the latter not so much. The visible effect was that line numbers reported for errors in a script file would be wrong if there were an earlier \copy that was reading anything other than inline-in-the-script-file data. To fix, introduce another pset field that holds the file do_copy wants the COPY code to use. This is a little bit ugly, but less so than passing the file down explicitly through several layers that aren't COPY-specific. Extracted from a larger patch by Kumar Rajeev Rastogi; that patch also changes printing of COPY command tags, which is not a bug fix and shouldn't get back-patched. This particular idea was from a suggestion by Amit Khandekar, if I'm reading the thread correctly. Back-patch to 9.2 where the faulty code was introduced.
* Allow logical decoding via the walsender interface.Robert Haas2014-03-103-6/+6
| | | | | | | | | | | | | | | In order for this to work, walsenders need the optional ability to connect to a database, so the "replication" keyword now allows true or false, for backward-compatibility, and the new value "database" (which causes the "dbname" parameter to be respected). walsender needs to loop not only when idle but also when sending decoded data to the user and when waiting for more xlog data to decode. This means that there are now three separate loops inside walsender.c; although some refactoring has been done here, this is still a bit ugly. Andres Freund, with contributions from Álvaro Herrera, and further review by me.
* Correct copy/pasto in comment for REPLICA IDENTITYSimon Riggs2014-03-091-1/+1
|
* pg_ctl: improve handling of invalid data directoryBruce Momjian2014-03-081-11/+37
| | | | | | | | | Return '4' and report a meaningful error message when a non-existent or invalid data directory is passed. Previously, pg_ctl would just report the server was not running. Patch by me and Amit Kapila Report from Peter Eisentraut
* pg_dump: make argument combination error exit code consistentBruce Momjian2014-03-051-2/+8
| | | | Per report from Pavel Golub
* Remove unused field "evttype".Tom Lane2014-03-051-1/+0
| | | | Apparent oversight in commit 3855968f.
* Allocate fresh memory for post_opts/exec_pathStephen Frost2014-03-051-2/+2
| | | | | | | | Instead of having read_post_opts() depend on the memory allocated for the config file (which is now getting free'd), pg_strdup() for post_opts and exec_path (similar to how it's being done elsewhere). Noted by Thom Brown.
* Fix issues with pg_ctlStephen Frost2014-03-051-5/+7
| | | | | | | | | The new, small, free_readfile managed to have bug in it which could cause it to try and free something it shouldn't, and fix the case where it was being called with an invalid pointer leading to a segfault. Noted by Bruce, issues introduced and fixed by me.
* Introduce logical decoding.Robert Haas2014-03-031-1/+4
| | | | | | | | | | | | | | | | | | | | | | This feature, building on previous commits, allows the write-ahead log stream to be decoded into a series of logical changes; that is, inserts, updates, and deletes and the transactions which contain them. It is capable of handling decoding even across changes to the schema of the effected tables. The output format is controlled by a so-called "output plugin"; an example is included. To make use of this in a real replication system, the output plugin will need to be modified to produce output in the format appropriate to that system, and to perform filtering. Currently, information can be extracted from the logical decoding system only via SQL; future commits will add the ability to stream changes via walsender. Andres Freund, with review and other contributions from many other people, including Álvaro Herrera, Abhijit Menon-Sen, Peter Gheogegan, Kevin Grittner, Robert Haas, Heikki Linnakangas, Fujii Masao, Abhijit Menon-Sen, Michael Paquier, Simon Riggs, Craig Ringer, and Steve Singer.
* Fix whitespacePeter Eisentraut2014-03-031-1/+1
|
* pg_dump et al: Add --if-exists optionAlvaro Herrera2014-03-035-5/+109
| | | | | | | | | | | | | This option makes pg_dump, pg_dumpall and pg_restore inject an IF EXISTS clause to each DROP command they emit. (In pg_dumpall, the clause is not added to individual objects drops, but rather to the CREATE DATABASE commands, as well as CREATE ROLE and CREATE TABLESPACE.) This allows for a better user dump experience when using --clean in case some objects do not already exist. Per bug #7873 by Dave Rolsky. Author: Pavel Stěhule Reviewed-by: Jeevan Chalke, Álvaro Herrera, Josh Kupershmidt
* Various Coverity-spotted fixesStephen Frost2014-03-017-39/+148
| | | | | | | | | | | | | | | | | | | | | | | | | | | A number of issues were identified by the Coverity scanner and are addressed in this patch. None of these appear to be security issues and many are mostly cosmetic changes. Short comments for each of the changes follows. Correct the semi-colon placement in be-secure.c regarding SSL retries. Remove a useless comparison-to-NULL in proc.c (value is dereferenced prior to this check and therefore can't be NULL). Add checking of chmod() return values to initdb. Fix a couple minor memory leaks in initdb. Fix memory leak in pg_ctl- involves free'ing the config file contents. Use an int to capture fgetc() return instead of an enum in pg_dump. Fix minor memory leaks in pg_dump. (note minor change to convertOperatorReference()'s API) Check fclose()/remove() return codes in psql. Check fstat(), find_my_exec() return codes in psql. Various ECPG memory leak fixes. Check find_my_exec() return in ECPG. Explicitly ignore pqFlush return in libpq error-path. Change PQfnumber() to avoid doing an strdup() when no changes required. Remove a few useless check-against-NULL's (value deref'd beforehand). Check rmtree(), malloc() results in pg_regress. Also check get_alternative_expectfile() return in pg_regress.
* Allow BASE_BACKUP to be throttledAlvaro Herrera2014-02-271-15/+119
| | | | | | | | | | | | | A new MAX_RATE option allows imposing a limit to the network transfer rate from the server side. This is useful to limit the stress that taking a base backup has on the server. pg_basebackup is now able to specify a value to the server, too. Author: Antonin Houska Patch reviewed by Stefan Radomski, Andres Freund, Zoltán Böszörményi, Fujii Masao, and Álvaro Herrera.
* psql: add separate \d display for disabled system triggersBruce Momjian2014-02-241-9/+27
| | | | | | | Previously if you disabled all triggers, only user triggers would show as disabled Per report from Andres Freund
* pg_dump: fix subtle memory leak in func and arg signature processingBruce Momjian2014-02-241-10/+9
|
* pg_basebackup: Add support for relocating tablespacesPeter Eisentraut2014-02-221-5/+161
| | | | | | | | Tablespaces can be relocated in plain backup mode by specifying one or more -T olddir=newdir options. Author: Steeve Lennmark <steevel@handeldsbanken.se> Reviewed-by: Peter Eisentraut <peter_e@gmx.net>
* Remove inappropriate EXPORTS line.Tom Lane2014-02-191-2/+0
| | | | Looks like this gets added later ...
* Avoid using dllwrap to build pgevent in Mingw builds.Tom Lane2014-02-192-17/+13
| | | | | | | If this works, we can get rid of configure's support for locating dllwrap ... but let's see what the buildfarm says, first. Hiroshi Inoue
* Prevent potential overruns of fixed-size buffers.Tom Lane2014-02-172-6/+6
| | | | | | | | | | | | | | | | | | | | | | | Coverity identified a number of places in which it couldn't prove that a string being copied into a fixed-size buffer would fit. We believe that most, perhaps all of these are in fact safe, or are copying data that is coming from a trusted source so that any overrun is not really a security issue. Nonetheless it seems prudent to forestall any risk by using strlcpy() and similar functions. Fixes by Peter Eisentraut and Jozef Mlich based on Coverity reports. In addition, fix a potential null-pointer-dereference crash in contrib/chkpass. The crypt(3) function is defined to return NULL on failure, but chkpass.c didn't check for that before using the result. The main practical case in which this could be an issue is if libc is configured to refuse to execute unapproved hashing algorithms (e.g., "FIPS mode"). This ideally should've been a separate commit, but since it touches code adjacent to one of the buffer overrun changes, I included it in this commit to avoid last-minute merge issues. This issue was reported by Honza Horak. Security: CVE-2014-0065 for buffer overruns, CVE-2014-0066 for crypt()
* Centralize getopt-related declarations in a new header file pg_getopt.h.Tom Lane2014-02-154-19/+2
| | | | | | | | | | | | We used to have externs for getopt() and its API variables scattered all over the place. Now that we find we're going to need to tweak the variable declarations for Cygwin, it seems like a good idea to have just one place to tweak. In this commit, the variables are declared "#ifndef HAVE_GETOPT_H". That may or may not work everywhere, but we'll soon find out. Andres Freund
* Remove use of sscanf in pg_upgrade, and add C comment to pg_dumpBruce Momjian2014-02-151-0/+1
| | | | Per report from Jackie Chang
* psql: Add C comment about gset_prefix being freed laterBruce Momjian2014-02-151-0/+1
|
* Clean up error cases in psql's COPY TO STDOUT/FROM STDIN code.Tom Lane2014-02-131-38/+37
| | | | | | | | | | | | | | | | | | | | | | | Adjust handleCopyOut() to stop trying to write data once it's failed one time. For typical cases such as out-of-disk-space or broken-pipe, additional attempts aren't going to do anything but waste time, and in any case clean truncation of the output seems like a better behavior than randomly dropping blocks in the middle. Also remove dubious (and misleadingly documented) attempt to force our way out of COPY_OUT state if libpq didn't do that. If we did have a situation like that, it'd be a bug in libpq and would be better fixed there, IMO. We can hope that commit fa4440f51628d692f077d54b8313aea31af087ea took care of any such problems, anyway. Also fix longstanding bug in handleCopyIn(): PQputCopyEnd() only supports a non-null errormsg parameter in protocol version 3, and will actively fail if one is passed in version 2. This would've made our attempts to get out of COPY_IN state after a failure into infinite loops when talking to pre-7.4 servers. Back-patch the COPY_OUT state change business back to 9.2 where it was introduced, and the other two fixes into all supported branches.
* Add missing include, required on some platformsMagnus Hagander2014-02-121-0/+1
| | | | Noted by the buildfarm and Andres Freund
* Kill pg_basebackup background process when exitingMagnus Hagander2014-02-123-6/+28
| | | | | | If an error occurs in the foreground (backup) process of pg_basebackup, and we exit in a controlled way, the background process (streaming xlog process) would stay around and keep streaming.
* scripts: Remove newlines from end of generated SQLPeter Eisentraut2014-02-109-19/+19
| | | | | | | | | This results in spurious empty lines in the server log. Instead, add the newlines only when printing out the --echo output. In some cases, this was already done, leading to two newlines being printed. Clean that up as well. From: Fabrízio de Royes Mello <fabriziomello@gmail.com>
* Further pg_dump / ftello improvementsStephen Frost2014-02-092-16/+4
| | | | | | | | | Make ftello error-checking consistent to all calls and remove a bit of ftello-related code which has been #if 0'd out since 2001. Note that we are not concerned with the ftello() call under snprintf() failing as it is just building a string to call exit_horribly() with; printing -1 in such a case is fine.
* Focus on ftello result < 0 instead of errnoStephen Frost2014-02-091-3/+2
| | | | | | | | Rather than reset errno (or just hope that its cleared already), check just the result of the ftello for < 0 to determine if there was an issue. Oversight by me, pointed out by Tom.
* Limit pg_basebackup progress output to 1/secondMagnus Hagander2014-02-091-10/+25
| | | | | | | | | This prevents pg_basebackup from generating excessive output when dumping large clusters. The status is now updated once / second, still making it possible to see that there is progress happening, but limiting the total bandwidth. Mika Eloranta, reviewed by Sawada Masahiko and Oskari Saarenmaa
* Avoid printing uninitialized filename variable in verbose modeMagnus Hagander2014-02-091-0/+1
| | | | | | | When using verbose mode for pg_basebackup, in tar format sent to stdout, we'd print an unitialized buffer as the filename. Reported by Pontus Lundkvist
* Minor pg_dump improvementsStephen Frost2014-02-083-9/+31
| | | | | | | | | Improve pg_dump by checking results on various fgetc() calls which previously were unchecked, ditto for ftello. Also clean up a couple of very minor memory leaks by waiting to allocate structures until after the initial check(s). Issues spotted by Coverity.