|
8 | 8 | * |
9 | 9 | * |
10 | 10 | * IDENTIFICATION |
11 | | - * $PostgreSQL: pgsql/src/backend/utils/init/postinit.c,v 1.211 2010/04/21 00:51:57 tgl Exp $ |
| 11 | + * $PostgreSQL: pgsql/src/backend/utils/init/postinit.c,v 1.212 2010/04/26 10:52:00 rhaas Exp $ |
12 | 12 | * |
13 | 13 | * |
14 | 14 | *------------------------------------------------------------------------- |
@@ -617,6 +617,37 @@ InitPostgres(const char *in_dbname, Oid dboid, const char *username, |
617 | 617 | am_superuser=superuser(); |
618 | 618 | } |
619 | 619 |
|
| 620 | +/* |
| 621 | + * If we're trying to shut down, only superusers can connect, and |
| 622 | + * new replication connections are not allowed. |
| 623 | + */ |
| 624 | +if ((!am_superuser||am_walsender)&& |
| 625 | +MyProcPort!=NULL&& |
| 626 | +MyProcPort->canAcceptConnections==CAC_WAITBACKUP) |
| 627 | +{ |
| 628 | +if (am_walsender) |
| 629 | +ereport(FATAL, |
| 630 | +(errcode(ERRCODE_INSUFFICIENT_PRIVILEGE), |
| 631 | +errmsg("new replication connections are not allowed during database shutdown"))); |
| 632 | +else |
| 633 | +ereport(FATAL, |
| 634 | +(errcode(ERRCODE_INSUFFICIENT_PRIVILEGE), |
| 635 | +errmsg("must be superuser to connect during database shutdown"))); |
| 636 | +} |
| 637 | + |
| 638 | +/* |
| 639 | + * The last few connections slots are reserved for superusers. |
| 640 | + * Although replication connections currently require superuser |
| 641 | + * privileges, we don't allow them to consume the reserved slots, |
| 642 | + * which are intended for interactive use. |
| 643 | + */ |
| 644 | +if ((!am_superuser||am_walsender)&& |
| 645 | +ReservedBackends>0&& |
| 646 | +!HaveNFreeProcs(ReservedBackends)) |
| 647 | +ereport(FATAL, |
| 648 | +(errcode(ERRCODE_TOO_MANY_CONNECTIONS), |
| 649 | +errmsg("remaining connection slots are reserved for non-replication superuser connections"))); |
| 650 | + |
620 | 651 | /* |
621 | 652 | * If walsender, we're done here --- we don't want to connect to any |
622 | 653 | * particular database. |
@@ -778,26 +809,6 @@ InitPostgres(const char *in_dbname, Oid dboid, const char *username, |
778 | 809 | if (!bootstrap) |
779 | 810 | CheckMyDatabase(dbname,am_superuser); |
780 | 811 |
|
781 | | -/* |
782 | | - * If we're trying to shut down, only superusers can connect. |
783 | | - */ |
784 | | -if (!am_superuser&& |
785 | | -MyProcPort!=NULL&& |
786 | | -MyProcPort->canAcceptConnections==CAC_WAITBACKUP) |
787 | | -ereport(FATAL, |
788 | | -(errcode(ERRCODE_INSUFFICIENT_PRIVILEGE), |
789 | | -errmsg("must be superuser to connect during database shutdown"))); |
790 | | - |
791 | | -/* |
792 | | - * Check a normal user hasn't connected to a superuser reserved slot. |
793 | | - */ |
794 | | -if (!am_superuser&& |
795 | | -ReservedBackends>0&& |
796 | | -!HaveNFreeProcs(ReservedBackends)) |
797 | | -ereport(FATAL, |
798 | | -(errcode(ERRCODE_TOO_MANY_CONNECTIONS), |
799 | | -errmsg("connection limit exceeded for non-superusers"))); |
800 | | - |
801 | 812 | /* |
802 | 813 | * Now process any command-line switches that were included in the startup |
803 | 814 | * packet, if we are in a regular backend.We couldn't do this before |
|