Rename Table

Learn how to rename a PostgreSQL table using the ALTER TABLE ... RENAME TO statement, including how dependent objects are handled.

4 min read · Last updated: March 2026 · Back to overview

Quick Answer

Use ALTER TABLE table_name RENAME TO new_table_name to rename a table. PostgreSQL automatically updates foreign key constraints, views, and indexes that reference the table. Use IF EXISTS to avoid errors when the table may not exist.

Spin up a Postgres database in 20 seconds with Vela.

Try Vela Sandbox

Renaming a table in PostgreSQL is a single-statement operation using ALTER TABLE ... RENAME TO. Unlike some databases, PostgreSQL automatically propagates the name change to all dependent objects — foreign key constraints, views, and indexes are updated to reference the new table name. The rename acquires an ACCESS EXCLUSIVE lock on the table but does not rewrite any data.

RENAME TABLE syntax

ALTER TABLE table_name RENAME TO new_table_name;

To avoid an error if the table does not exist:

ALTER TABLE IF EXISTS table_name RENAME TO new_table_name;

There is no syntax to rename multiple tables in a single statement — use separate ALTER TABLE ... RENAME TO statements for each.

Rename table examples

Example 1 — basic rename:

CREATE TABLE vendors (
  id   SERIAL PRIMARY KEY,
  name VARCHAR NOT NULL
);

ALTER TABLE vendors RENAME TO suppliers;

Inspect the renamed table in psql:

d suppliers

        Table "public.suppliers"
 Column |       Type        | Nullable |               Default
--------+-------------------+----------+-------------------------------------
 id     | integer           | not null | nextval('vendors_id_seq'::regclass)
 name   | character varying | not null |
Indexes:
    "vendors_pkey" PRIMARY KEY, btree (id)

Notice the sequence (vendors_id_seq) and the index name (vendors_pkey) retain the original names. Only the table name itself changes.

Example 2 — rename a table that has dependent objects:

CREATE TABLE customer_groups (
  id   SERIAL PRIMARY KEY,
  name VARCHAR NOT NULL
);

CREATE TABLE customers (
  id       SERIAL PRIMARY KEY,
  name     VARCHAR(255) NOT NULL,
  group_id INT NOT NULL,
  FOREIGN KEY (group_id) REFERENCES customer_groups (id)
    ON DELETE CASCADE ON UPDATE CASCADE
);

CREATE VIEW customer_data AS
  SELECT c.id, c.name, g.name AS customer_group
  FROM customers c
  INNER JOIN customer_groups g ON g.id = c.group_id;

-- Rename the referenced table
ALTER TABLE customer_groups RENAME TO groups;

After the rename, both the foreign key and the view are automatically updated:

-- Foreign key now references "groups"
d customers
...
Foreign-key constraints:
    "customers_group_id_fkey" FOREIGN KEY (group_id) REFERENCES groups(id)

-- View definition updated automatically
d+ customer_data
...
 FROM customers c
   JOIN groups g ON g.id = c.group_id;

Rename table tips

  • The sequence created by SERIAL keeps its original name (e.g., old_table_id_seq) after the table rename. If naming consistency matters, rename the sequence separately with ALTER SEQUENCE old_seq RENAME TO new_seq.
  • Existing index names also retain the original table name prefix. Rename them with ALTER INDEX old_index_name RENAME TO new_index_name if desired.
  • Always test renames in a staging environment first — application code or stored procedures that reference the old table name will break and must be updated.
  • You cannot rename multiple tables in a single statement. Each rename requires a separate ALTER TABLE call.

Reference: PostgreSQL documentation — ALTER TABLE.

Continue in Managing Tables: Add Column.

Related in this section: PostgreSQL Data Types · Create Table · Select Into

Frequently Asked Questions

Does renaming a table break views and foreign keys?

No. PostgreSQL automatically updates views and foreign key constraints to reference the new table name. The internal object identifier (OID) remains unchanged, so all dependencies follow the rename transparently.

Does renaming a table rename its sequences and indexes?

No. Sequences and indexes created for the table (such as those backing SERIAL columns or PRIMARY KEY constraints) keep their original names after the table rename. You must rename them separately with ALTER SEQUENCE and ALTER INDEX if consistency is important.

How do I rename a table only if it exists?

Use IF EXISTS: ALTER TABLE IF EXISTS old_name RENAME TO new_name. If the table does not exist, PostgreSQL issues a NOTICE rather than an error.

Can I rename multiple tables in one statement?

No. Each table requires its own ALTER TABLE ... RENAME TO statement. There is no batch rename syntax in PostgreSQL.

Does renaming a table require a table rewrite?

No. Renaming a table is a metadata-only operation. PostgreSQL updates the table name in the system catalog (pg_class) without touching any data pages. It does acquire an ACCESS EXCLUSIVE lock for the duration of the rename.