|
13 | 13 | *
|
14 | 14 | * Copyright (c) 2001-2007, PostgreSQL Global Development Group
|
15 | 15 | *
|
16 |
| - * $PostgreSQL: pgsql/src/backend/postmaster/pgstat.c,v 1.156 2007/05/27 03:50:39 tgl Exp $ |
| 16 | + * $PostgreSQL: pgsql/src/backend/postmaster/pgstat.c,v 1.157 2007/05/27 05:37:49 tgl Exp $ |
17 | 17 | * ----------
|
18 | 18 | */
|
19 | 19 | #include "postgres.h"
|
@@ -1771,28 +1771,45 @@ CreateSharedBackendStatus(void)
|
1771 | 1771 | }
|
1772 | 1772 |
|
1773 | 1773 |
|
| 1774 | +/* ---------- |
| 1775 | + * pgstat_initialize() - |
| 1776 | + * |
| 1777 | + * Initialize pgstats state, and set up our on-proc-exit hook. |
| 1778 | + * Called from InitPostgres. MyBackendId must be set, |
| 1779 | + * but we must not have started any transaction yet (since the |
| 1780 | + * exit hook must run after the last transaction exit). |
| 1781 | + * ---------- |
| 1782 | + */ |
| 1783 | +void |
| 1784 | +pgstat_initialize(void) |
| 1785 | +{ |
| 1786 | + /* Initialize MyBEEntry */ |
| 1787 | + Assert(MyBackendId >= 1 && MyBackendId <= MaxBackends); |
| 1788 | + MyBEEntry = &BackendStatusArray[MyBackendId - 1]; |
| 1789 | + |
| 1790 | + /* Set up a process-exit hook to clean up */ |
| 1791 | + on_shmem_exit(pgstat_beshutdown_hook, 0); |
| 1792 | +} |
| 1793 | + |
1774 | 1794 | /* ----------
|
1775 | 1795 | * pgstat_bestart() -
|
1776 | 1796 | *
|
1777 |
| - * Initialize this backend's entry in the PgBackendStatus array, |
1778 |
| - * and set up an on-proc-exit hook that will clear it again. |
1779 |
| - * Called from InitPostgres. MyBackendId and MyDatabaseId must be set. |
| 1797 | + * Initialize this backend's entry in the PgBackendStatus array. |
| 1798 | + * Called from InitPostgres. MyDatabaseId and session userid must be set |
| 1799 | + * (hence, this cannot be combined with pgstat_initialize). |
1780 | 1800 | * ----------
|
1781 | 1801 | */
|
1782 | 1802 | void
|
1783 | 1803 | pgstat_bestart(void)
|
1784 | 1804 | {
|
1785 |
| - volatile PgBackendStatus *beentry; |
1786 | 1805 | TimestampTz proc_start_timestamp;
|
1787 | 1806 | Oid userid;
|
1788 | 1807 | SockAddr clientaddr;
|
1789 |
| - |
1790 |
| - Assert(MyBackendId >= 1 && MyBackendId <= MaxBackends); |
1791 |
| - MyBEEntry = &BackendStatusArray[MyBackendId - 1]; |
| 1808 | + volatile PgBackendStatus *beentry; |
1792 | 1809 |
|
1793 | 1810 | /*
|
1794 |
| - * To minimize the time spent modifying the entry, fetch all the needed |
1795 |
| - * data first. |
| 1811 | + * To minimize the time spent modifying the PgBackendStatus entry, |
| 1812 | + * fetch all the needed data first. |
1796 | 1813 | *
|
1797 | 1814 | * If we have a MyProcPort, use its session start time (for consistency,
|
1798 | 1815 | * and to save a kernel call).
|
@@ -1839,11 +1856,6 @@ pgstat_bestart(void)
|
1839 | 1856 |
|
1840 | 1857 | beentry->st_changecount++;
|
1841 | 1858 | Assert((beentry->st_changecount & 1) == 0);
|
1842 |
| - |
1843 |
| - /* |
1844 |
| - * Set up a process-exit hook to clean up. |
1845 |
| - */ |
1846 |
| - on_shmem_exit(pgstat_beshutdown_hook, 0); |
1847 | 1859 | }
|
1848 | 1860 |
|
1849 | 1861 | /*
|
|
0 commit comments