Blog Post

Azure Database Support Blog
2 MIN READ

Azure PostgreSQL Lesson Learned#7: Database Missing After Planned Maintenance

angesalsaa's avatar
angesalsaa
Icon for Microsoft rankMicrosoft
Nov 18, 2025

A customer reported an issue when attempting to connect to a specific user database after a maintenance window: FATAL: database 'xyz' does not exist DETAIL: The database subdirectory 'pg_tblspc/.../PG_..../...' is missing. This error typically occurs when the database was created under a temporary tablespace, which is not backed up during maintenance or server restarts.

Co‑authored with HaiderZ-MSFT​

Overview

If you’re running Azure Database for PostgreSQL Flexible Server, you might encounter a scenario where your database disappears after planned maintenance. This blog explains:

  • Root cause of the issue
  • Troubleshooting steps
  • Best practices to prevent data loss
Symptoms

After a maintenance window, customers reported connection failures with errors like:

connection failed: connection to server at 'IP', port 5432 failed: FATAL: database 'databaseName' does not exist DETAIL: The database subdirectory 'pg_tblspc/.../PG_...' is missing.

Even after a successful restore, the database remains inaccessible!

Root Cause

The missing database files were located in a temporary tablespace.

On Azure Database for PostgreSQL Flexible Server:

  • A default temporary tablespace is created for internal operations (e.g., sorting).
  • It is not backed up during maintenance, restarts, or HA failovers.
  • If permanent objects or entire databases are created in this temporary tablespace, they will be lost after:
    • Planned maintenance windows
    • Server restarts
    • High availability failovers

Important: Temporary tablespaces are designed for transient data only. Storing persistent objects here is unsafe. [Limits in...soft Learn | External], [Overview o...soft Learn | External]

Operational Checks

To confirm if a database uses a temporary tablespace:

select datname, dattablespace from pg_database where datname = '<dbname>';

Compare dattablespace OID with pg_tablespace:

select oid, spcname, spcowner from pg_tablespace

If OID matches temptblspace, the database resides in a temporary tablespace.

Mitigation

Unfortunately, data cannot be recovered because temporary tablespaces are excluded from backups during maintenance activities or server restarts.

Recommended actions:

  • Do not create permanent objects or databases in temporary tablespaces.
  • Always use the default tablespace inherited from the template database.

Prevention & Best Practices

Why This Matters

Creating databases in temporary tablespaces leads to:

  • Permanent data loss after maintenance.
  • Failed connections and restore attempts.
  • Operational disruption and downtime.

Key Takeaways

  • Issue: Databases created in temporary tablespace are lost after maintenance, restarts, or HA failovers.
  • Fix: Use default tablespace for all permanent objects.
  • Best Practice: Never store persistent data in temporary tablespace.
Updated Nov 19, 2025
Version 2.0

2 Comments

  • Rizwan_Siddiqui's avatar
    Rizwan_Siddiqui
    Copper Contributor

    Learnt something really important today and it's shows how important is to focus on such detail while configuring or customising the db. Thank you. Keep posting.

    • angesalsaa's avatar
      angesalsaa
      Icon for Microsoft rankMicrosoft

      Thank you for sharing your thoughts! Absolutely, this is essential for your database reliability and continuity. Glad the post was helpful! We’ll keep sharing more insights to help avoid hidden pitfalls.