diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2013-03-16 23:22:17 -0400 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2013-03-16 23:22:57 -0400 |
commit | d43837d03067487560af481474ae985df894f786 (patch) | |
tree | 7289d038a184fa3dc59195aaa27538714ea85ad9 /src/backend/utils/init/postinit.c | |
parent | d2bef5f7db5f3afdbbb3f58b8eff49f0bc7ef790 (diff) |
Add lock_timeout configuration parameter.
This GUC allows limiting the time spent waiting to acquire any one
heavyweight lock.
In support of this, improve the recently-added timeout infrastructure
to permit efficiently enabling or disabling multiple timeouts at once.
That reduces the performance hit from turning on lock_timeout, though
it's still not zero.
Zoltán Böszörményi, reviewed by Tom Lane,
Stephen Frost, and Hari Babu
Diffstat (limited to 'src/backend/utils/init/postinit.c')
-rw-r--r-- | src/backend/utils/init/postinit.c | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/src/backend/utils/init/postinit.c b/src/backend/utils/init/postinit.c index 84270061d8a..5f8f98b5e03 100644 --- a/src/backend/utils/init/postinit.c +++ b/src/backend/utils/init/postinit.c @@ -67,6 +67,7 @@ static void CheckMyDatabase(const char *name, bool am_superuser); static void InitCommunication(void); static void ShutdownPostgres(int code, Datum arg); static void StatementTimeoutHandler(void); +static void LockTimeoutHandler(void); static bool ThereIsAtLeastOneRole(void); static void process_startup_options(Port *port, bool am_superuser); static void process_settings(Oid databaseid, Oid roleid); @@ -535,6 +536,7 @@ InitPostgres(const char *in_dbname, Oid dboid, const char *username, { RegisterTimeout(DEADLOCK_TIMEOUT, CheckDeadLock); RegisterTimeout(STATEMENT_TIMEOUT, StatementTimeoutHandler); + RegisterTimeout(LOCK_TIMEOUT, LockTimeoutHandler); } /* @@ -1052,6 +1054,22 @@ StatementTimeoutHandler(void) kill(MyProcPid, SIGINT); } +/* + * LOCK_TIMEOUT handler: trigger a query-cancel interrupt. + * + * This is identical to StatementTimeoutHandler, but since it's so short, + * we might as well keep the two functions separate for clarity. + */ +static void +LockTimeoutHandler(void) +{ +#ifdef HAVE_SETSID + /* try to signal whole process group */ + kill(-MyProcPid, SIGINT); +#endif + kill(MyProcPid, SIGINT); +} + /* * Returns true if at least one role is defined in this database cluster. |