> This page location: Administration Tips > Check PostgreSQL Uptime
> Full Neon documentation index: https://neon.com/docs/llms.txt

# PostgreSQL Uptime

**Summary**: in this tutorial, you will learn how to calculate the PostgreSQL uptime based on the current time and the server's started time.

## Checking PostgreSQL uptime

First, open the Command Prompt on Windows or Terminal on Unix-like systems and connect to the PostgreSQL server:

```bash
psql -U postgres
```

Second, execute the following query to get the PostgreSQL uptime:

```sql
SELECT
  date_trunc(
    'second',
    current_timestamp - pg_postmaster_start_time()
  ) as uptime;
```

How it works

PostgreSQL stores the time when it was started in the database server. To retrieve the start time, you use the `pg_postmaster_start_time()` function as follows:

```sql
SELECT pg_postmaster_start_time();
```

Output:

```text
   pg_postmaster_start_time
-------------------------------
 2024-02-14 03:41:32.048451-07
(1 row)
```

You can then calculate the uptime based on the current time and the start time returned by the `pg_postmaster_start_time()` function:

```sql
SELECT current_timestamp - pg_postmaster_start_time() uptime;
```

Output:

```text
         uptime
------------------------
 6 days 07:39:06.006459
(1 row)
```

You can truncate the microsecond from the uptime using the [`DATE_TRUNC()`](../postgresql-date-functions/postgresql-date_trunc) function to make the output more human-readable:

```sql
SELECT
  date_trunc(
    'second',
    current_timestamp - pg_postmaster_start_time()
  ) as uptime;
```

Output:

```
     uptime
-----------------
 6 days 07:39:24
(1 row)
```

## Summary

- Calculate the PostgreSQL uptime using the current time and start time.

---

## Related docs (Administration Tips)

- [Reset Password](https://neon.com/postgresql/postgresql-administration/postgresql-reset-password)
- [Describe Table](https://neon.com/postgresql/postgresql-administration/postgresql-describe-table)
- [Show Databases](https://neon.com/postgresql/postgresql-administration/postgresql-show-databases)
- [Show Tables](https://neon.com/postgresql/postgresql-administration/postgresql-show-tables)
- [Practical psql Commands](https://neon.com/postgresql/postgresql-administration/psql-commands)
- [Restart PostgreSQL on Windows](https://neon.com/postgresql/postgresql-administration/restart-postgresql-windows)
- [Restart PostgreSQL on Ubuntu](https://neon.com/postgresql/postgresql-administration/postgresql-restart-ubuntu)
- [Get PostgreSQL Version](https://neon.com/postgresql/postgresql-administration/postgresql-version)
- [Password File (.pgpass)](https://neon.com/postgresql/postgresql-administration/postgresql-password-file-pgpass)
- [Terminate Backend Connections](https://neon.com/postgresql/postgresql-administration/postgresql-pg_terminate_backend)
- [Uninstall PostgreSQL on Ubuntu](https://neon.com/postgresql/postgresql-administration/uninstall-postgresql-ubuntu)
