~ubuntu-branches/ubuntu/quantal/postgresql-9.1/quantal-updates

« back to all changes in this revision

Viewing changes to src/backend/replication/walsender.c

  • Committer: Package Import Robot
  • Author(s): Martin Pitt
  • Date: 2012-06-04 06:47:45 UTC
  • mfrom: (1.1.8)
  • Revision ID: package-import@ubuntu.com-20120604064745-dvs00jnur0vgkwqs
Tags: 9.1.4-1
* Urgency medium due to security fixes.
* New upstream bug fix/security release:
  - Fix incorrect password transformation in "contrib/pgcrypto"'s DES
    crypt() function.
    If a password string contained the byte value 0x80, the remainder
    of the password was ignored, causing the password to be much weaker
    than it appeared. With this fix, the rest of the string is properly
    included in the DES hash. Any stored password values that are
    affected by this bug will thus no longer match, so the stored
    values may need to be updated. (CVE-2012-2143)
  - Ignore SECURITY DEFINER and SET attributes for a procedural
    language's call handler. Applying such attributes to a call handler
    could crash the server. (CVE-2012-2655)
  - Make "contrib/citext"'s upgrade script fix collations of citext
    arrays and domains over citext.
    Release 9.1.2 provided a fix for collations of citext columns and
    indexes in databases upgraded or reloaded from pre-9.1
    installations, but that fix was incomplete: it neglected to handle
    arrays and domains over citext. This release extends the module's
    upgrade script to handle these cases. As before, if you have
    already run the upgrade script, you'll need to run the collation
    update commands by hand instead. See the 9.1.2 release notes for
    more information about doing this.
  - Allow numeric timezone offsets in timestamp input to be up to 16
    hours away from UTC. Some historical time zones have offsets larger than
    15 hours, the previous limit. This could result in dumped data values
    being rejected during reload.
  - Fix timestamp conversion to cope when the given time is exactly the
    last DST transition time for the current timezone.
    This oversight has been there a long time, but was not noticed
    previously because most DST-using zones are presumed to have an
    indefinite sequence of future DST transitions.
  - Fix text to name and char to name casts to perform string
    truncation correctly in multibyte encodings.
  - Fix memory copying bug in to_tsquery().
  - Ensure txid_current() reports the correct epoch when executed in
    hot standby.
  - Fix planner's handling of outer PlaceHolderVars within subqueries.
    This bug concerns sub-SELECTs that reference variables coming from
    the nullable side of an outer join of the surrounding query. In
    9.1, queries affected by this bug would fail with "ERROR:
    Upper-level PlaceHolderVar found where not expected". But in 9.0
    and 8.4, you'd silently get possibly-wrong answers, since the value
    transmitted into the subquery wouldn't go to null when it should.
  - Fix planning of UNION ALL subqueries with output columns that are
    not simple variables.
    Planning of such cases got noticeably worse in 9.1 as a result of a
    misguided fix for "MergeAppend child's targetlist doesn't match
    MergeAppend" errors. Revert that fix and do it another way.
  - Fix slow session startup when pg_attribute is very large.
    If pg_attribute exceeds one-fourth of shared_buffers, cache
    rebuilding code that is sometimes needed during session start would
    trigger the synchronized-scan logic, causing it to take many times
    longer than normal. The problem was particularly acute if many new
    sessions were starting at once.
  - Ensure sequential scans check for query cancel reasonably often.
    A scan encountering many consecutive pages that contain no live
    tuples would not respond to interrupts meanwhile.
  - Ensure the Windows implementation of PGSemaphoreLock() clears
    ImmediateInterruptOK before returning.
    This oversight meant that a query-cancel interrupt received later
    in the same query could be accepted at an unsafe time, with
    unpredictable but not good consequences.
  - Show whole-row variables safely when printing views or rules.
    Corner cases involving ambiguous names (that is, the name could be
    either a table or column name of the query) were printed in an
    ambiguous way, risking that the view or rule would be interpreted
    differently after dump and reload. Avoid the ambiguous case by
    attaching a no-op cast.
  - Fix "COPY FROM" to properly handle null marker strings that
    correspond to invalid encoding.
    A null marker string such as E'\\0' should work, and did work in
    the past, but the case got broken in 8.4.
  - Fix "EXPLAIN VERBOSE" for writable CTEs containing RETURNING
    clauses.
  - Fix "PREPARE TRANSACTION" to work correctly in the presence of
    advisory locks.
    Historically, "PREPARE TRANSACTION" has simply ignored any
    session-level advisory locks the session holds, but this case was
    accidentally broken in 9.1.
  - Fix truncation of unlogged tables.
  - Ignore missing schemas during non-interactive assignments of
    search_path.
    This re-aligns 9.1's behavior with that of older branches.
    Previously 9.1 would throw an error for nonexistent schemas
    mentioned in search_path settings obtained from places such as
    "ALTER DATABASE SET".
  - Fix bugs with temporary or transient tables used in extension
    scripts.
    This includes cases such as a rewriting "ALTER TABLE" within an
    extension update script, since that uses a transient table behind
    the scenes.
  - Ensure autovacuum worker processes perform stack depth checking
    properly.
    Previously, infinite recursion in a function invoked by
    auto-"ANALYZE" could crash worker processes.
  - Fix logging collector to not lose log coherency under high load.
    The collector previously could fail to reassemble large messages if
    it got too busy.
  - Fix logging collector to ensure it will restart file rotation after
    receiving SIGHUP.
  - Fix "too many LWLocks taken" failure in GiST indexes.
  - Fix WAL replay logic for GIN indexes to not fail if the index was
    subsequently dropped.
  - Correctly detect SSI conflicts of prepared transactions after a
    crash.
  - Avoid synchronous replication delay when committing a transaction
    that only modified temporary tables.
    In such a case the transaction's commit record need not be flushed
    to standby servers, but some of the code didn't know that and
    waited for it to happen anyway.
  - Fix error handling in pg_basebackup.
  - Fix walsender to not go into a busy loop if connection is
    terminated.
  - Fix memory leak in PL/pgSQL's "RETURN NEXT" command.
  - Fix PL/pgSQL's "GET DIAGNOSTICS" command when the target is the
    function's first variable.
  - Ensure that PL/Perl package-qualifies the _TD variable.
    This bug caused trigger invocations to fail when they are nested
    within a function invocation that changes the current package.
  - Fix PL/Python functions returning composite types to accept a
    string for their result value.
    This case was accidentally broken by the 9.1 additions to allow a
    composite result value to be supplied in other formats, such as
    dictionaries.
  - Fix potential access off the end of memory in psql's expanded
    display ("\x") mode.
  - Fix several performance problems in pg_dump when the database
    contains many objects.
    pg_dump could get very slow if the database contained many schemas,
    or if many objects are in dependency loops, or if there are many
    owned sequences.
  - Fix memory and file descriptor leaks in pg_restore when reading a
    directory-format archive.
  - Fix pg_upgrade for the case that a database stored in a non-default
    tablespace contains a table in the cluster's default tablespace.
  - In ecpg, fix rare memory leaks and possible overwrite of one byte
    after the sqlca_t structure.
  - Fix "contrib/dblink"'s dblink_exec() to not leak temporary database
    connections upon error.
  - Fix "contrib/dblink" to report the correct connection name in error
    messages.
  - Fix "contrib/vacuumlo" to use multiple transactions when dropping
    many large objects.
    This change avoids exceeding max_locks_per_transaction when many
    objects need to be dropped. The behavior can be adjusted with the
    new -l (limit) option.
* debian/control: Bump debhelper build dependency to >= 8, as it does not
  build with earlier versions.
* debian/control: Move bzr branches to alioth, so that other members of
  pkg-postgresql can commit. Update Vcs-* tags.
* debian/control: Set Maintainer: to pkg-postgresql group, and move myself
  to Uploaders:.

Show diffs side-by-side

added added

removed removed

Lines of Context:
476
476
{
477
477
        unsigned char firstchar;
478
478
        int                     r;
479
 
        int                     received = false;
 
479
        bool            received = false;
480
480
 
481
481
        for (;;)
482
482
        {
700
700
        /* Loop forever, unless we get an error */
701
701
        for (;;)
702
702
        {
 
703
                /* Clear any already-pending wakeups */
 
704
                ResetLatch(&MyWalSnd->latch);
 
705
 
703
706
                /*
704
707
                 * Emergency bailout if postmaster has died.  This is to avoid the
705
708
                 * necessity for manual cleanup of all postmaster children.
718
721
                /* Normal exit from the walsender is here */
719
722
                if (walsender_shutdown_requested)
720
723
                {
721
 
                        /* Inform the standby that XLOG streaming was done */
 
724
                        /* Inform the standby that XLOG streaming is done */
722
725
                        pq_puttextmessage('C', "COPY 0");
723
726
                        pq_flush();
724
727
 
725
728
                        proc_exit(0);
726
729
                }
727
730
 
 
731
                /* Check for input from the client */
 
732
                ProcessRepliesIfAny();
 
733
 
728
734
                /*
729
735
                 * If we don't have any pending data in the output buffer, try to send
730
 
                 * some more.
 
736
                 * some more.  If there is some, we don't bother to call XLogSend
 
737
                 * again until we've flushed it ... but we'd better assume we are not
 
738
                 * caught up.
731
739
                 */
732
740
                if (!pq_is_send_pending())
 
741
                        XLogSend(output_message, &caughtup);
 
742
                else
 
743
                        caughtup = false;
 
744
 
 
745
                /* Try to flush pending output to the client */
 
746
                if (pq_flush_if_writable() != 0)
 
747
                        break;
 
748
 
 
749
                /* If nothing remains to be sent right now ... */
 
750
                if (caughtup && !pq_is_send_pending())
733
751
                {
734
 
                        XLogSend(output_message, &caughtup);
735
 
 
736
 
                        /*
737
 
                         * Even if we wrote all the WAL that was available when we started
738
 
                         * sending, more might have arrived while we were sending this
739
 
                         * batch. We had the latch set while sending, so we have not
740
 
                         * received any signals from that time. Let's arm the latch again,
741
 
                         * and after that check that we're still up-to-date.
742
 
                         */
743
 
                        if (caughtup && !pq_is_send_pending())
744
 
                        {
745
 
                                ResetLatch(&MyWalSnd->latch);
746
 
 
 
752
                        /*
 
753
                         * If we're in catchup state, move to streaming.  This is an
 
754
                         * important state change for users to know about, since before
 
755
                         * this point data loss might occur if the primary dies and we
 
756
                         * need to failover to the standby. The state change is also
 
757
                         * important for synchronous replication, since commits that
 
758
                         * started to wait at that point might wait for some time.
 
759
                         */
 
760
                        if (MyWalSnd->state == WALSNDSTATE_CATCHUP)
 
761
                        {
 
762
                                ereport(DEBUG1,
 
763
                                                (errmsg("standby \"%s\" has now caught up with primary",
 
764
                                                                application_name)));
 
765
                                WalSndSetState(WALSNDSTATE_STREAMING);
 
766
                        }
 
767
 
 
768
                        /*
 
769
                         * When SIGUSR2 arrives, we send any outstanding logs up to the
 
770
                         * shutdown checkpoint record (i.e., the latest record) and exit.
 
771
                         * This may be a normal termination at shutdown, or a promotion,
 
772
                         * the walsender is not sure which.
 
773
                         */
 
774
                        if (walsender_ready_to_stop)
 
775
                        {
 
776
                                /* ... let's just be real sure we're caught up ... */
747
777
                                XLogSend(output_message, &caughtup);
 
778
                                if (caughtup && !pq_is_send_pending())
 
779
                                {
 
780
                                        walsender_shutdown_requested = true;
 
781
                                        continue;               /* don't want to wait more */
 
782
                                }
748
783
                        }
749
784
                }
750
785
 
751
 
                /* Flush pending output to the client */
752
 
                if (pq_flush_if_writable() != 0)
753
 
                        break;
754
 
 
755
786
                /*
756
 
                 * When SIGUSR2 arrives, we send any outstanding logs up to the
757
 
                 * shutdown checkpoint record (i.e., the latest record) and exit.
 
787
                 * We don't block if not caught up, unless there is unsent data
 
788
                 * pending in which case we'd better block until the socket is
 
789
                 * write-ready.  This test is only needed for the case where XLogSend
 
790
                 * loaded a subset of the available data but then pq_flush_if_writable
 
791
                 * flushed it all --- we should immediately try to send more.
758
792
                 */
759
 
                if (walsender_ready_to_stop && !pq_is_send_pending())
760
 
                {
761
 
                        XLogSend(output_message, &caughtup);
762
 
                        ProcessRepliesIfAny();
763
 
                        if (caughtup && !pq_is_send_pending())
764
 
                                walsender_shutdown_requested = true;
765
 
                }
766
 
 
767
 
                if ((caughtup || pq_is_send_pending()) &&
768
 
                        !got_SIGHUP &&
769
 
                        !walsender_shutdown_requested)
 
793
                if (caughtup || pq_is_send_pending())
770
794
                {
771
795
                        TimestampTz finish_time = 0;
772
 
                        long            sleeptime;
 
796
                        long            sleeptime = -1;
773
797
 
774
 
                        /* Reschedule replication timeout */
 
798
                        /* Determine time until replication timeout */
775
799
                        if (replication_timeout > 0)
776
800
                        {
777
801
                                long            secs;
795
819
                                sleeptime = WalSndDelay;
796
820
                        }
797
821
 
798
 
                        /* Sleep */
 
822
                        /* Sleep until something happens or replication timeout */
799
823
                        WaitLatchOrSocket(&MyWalSnd->latch, MyProcPort->sock,
800
824
                                                          true, pq_is_send_pending(),
801
825
                                                          sleeptime);
802
826
 
803
 
                        /* Check for replication timeout */
 
827
                        /*
 
828
                         * Check for replication timeout.  Note we ignore the corner case
 
829
                         * possibility that the client replied just as we reached the
 
830
                         * timeout ... he's supposed to reply *before* that.
 
831
                         */
804
832
                        if (replication_timeout > 0 &&
805
833
                                GetCurrentTimestamp() >= finish_time)
806
834
                        {
814
842
                                break;
815
843
                        }
816
844
                }
817
 
 
818
 
                /*
819
 
                 * If we're in catchup state, see if its time to move to streaming.
820
 
                 * This is an important state change for users, since before this
821
 
                 * point data loss might occur if the primary dies and we need to
822
 
                 * failover to the standby. The state change is also important for
823
 
                 * synchronous replication, since commits that started to wait at that
824
 
                 * point might wait for some time.
825
 
                 */
826
 
                if (MyWalSnd->state == WALSNDSTATE_CATCHUP && caughtup)
827
 
                {
828
 
                        ereport(DEBUG1,
829
 
                                        (errmsg("standby \"%s\" has now caught up with primary",
830
 
                                                        application_name)));
831
 
                        WalSndSetState(WALSNDSTATE_STREAMING);
832
 
                }
833
 
 
834
 
                ProcessRepliesIfAny();
835
845
        }
836
846
 
837
847
        /*