Debian – Risk of starting NTP on database server

debianntppostgresqltime

I've heard rumors of bad things happening to database and mail servers if you change the system time while they are running. However, I'm having a hard time finding any concrete information on actual risks.

I have a production Postgres 9.3 server running on a Debian Wheezy host and the time is off by 367 seconds. Can I just run ntpdate or start openntp while Postgres is running, or is that likely to cause an issue? If so, what is a safer method of correcting the time?

Are there other services that are more sensitive to a change in system time? Maybe mail servers (exim, sendmail, etc) or message queues (activemq, rabbitmq, zeromq, etc)?

Best Answer

Databases don't like backward steps in time, so you don't want to start with the default behavior of jumping the time. Adding the -x option to the command line will slew the time if the offset is less than 600 seconds (10 minutes). At maximum slew rate it will take about a day and half to adjust the clock by a minute. This is a slow but safe way to adjust the time.

Before running ntp to adjust the time, you may want start ntp with a option like -g 2 to verify how large an offset it is detecting. This will set the panic offset to 2 seconds which should be relatively safe.

An alternative option I have used before this option was available was to write a loop that reset the clock back part of second every minute or so. If you check to ensure the reset won't change the second this is likely safe. If you use timestamps heavily, you may have out of sequence records.

A common option is to shutdown the server long enough that there is no backward movement of the clock. ntp or ntpdate can be configured to jump the clock to the correct time at start up. This should be done before the database is started.