pg_sysdatetime
pg_sysdatetime · High-precision SQL Server-style system datetime functions for PostgreSQL, mainly useful on older Windows builds.
Overview
| ID | Extension | Package | Version | Category | License | Language |
|---|---|---|---|---|---|---|
| 100291 | pg_sysdatetime | pg_sysdatetime | 1.0 | SIM | BSD-2-Clause | C |
Usage
Sources:
pg_sysdatetime provides SQL Server-style current-time functions for PostgreSQL 9.4 and older, primarily to improve timestamp precision on Windows. PostgreSQL 9.5 added native use of the precise Windows clock where available, so modern PostgreSQL installations do not need this deprecated extension.
Functions
sysutcdatetime() returns UTC as timestamp without time zone. sysdatetime() returns local wall-clock time, also without a time-zone marker, using the session TimeZone. sysdatetimeoffset() returns the current instant as timestamp with time zone. Do not compare the first two values without accounting for their different implied zones.
Windows Timer Setting
On old Windows systems, a superuser can request a finer system timer interval:
The setting can be reloaded and can also be changed by a superuser per session. It affects the operating system’s timer behavior and power use, so measure the system-wide effect before enabling it.
The extension does not call GetSystemTimePreciseAsFileTime. Before Windows 8 and Windows Server 2012, the underlying clock can still advance only once per millisecond; extra displayed digits therefore do not imply extra accuracy. For migration, replace these names with small SQL wrappers around PostgreSQL’s native clock functions, and verify time-zone and volatility semantics expected by the application.