Goal Find foreign data wrappers that do not have any associated foreign servers.
Type Problem detection (Each row in the result could represent a flaw in the design)
Reliability High (Few or no false-positive results)
License MIT (opens in new tab)
Fixing Suggestion Drop the foreign data wrapper or start to use it.
Data Source INFORMATION_SCHEMA only
SQL Query
SELECT foreign_data_wrapper_name
FROM INFORMATION_SCHEMA.foreign_data_wrappers AS fdw
WHERE NOT EXISTS (SELECT 1
FROM INFORMATION_SCHEMA.foreign_servers AS fs
WHERE fdw.foreign_data_wrapper_name=fs.foreign_data_wrapper_name)
ORDER BY foreign_data_wrapper_name;

SQL statements that help generate fixes for the identified problem.

Fix Action #1
SELECT format('DROP FOREIGN DATA WRAPPER %1$I;', foreign_data_wrapper_name) AS statements
FROM INFORMATION_SCHEMA.foreign_data_wrappers AS fdw
WHERE NOT EXISTS (SELECT 1
FROM INFORMATION_SCHEMA.foreign_servers AS fs
WHERE fdw.foreign_data_wrapper_name=fs.foreign_data_wrapper_name)
ORDER BY foreign_data_wrapper_name;

Drop the foreign data wrapper.

SQL Query to Generate FixDescription
SELECT format('DROP FOREIGN DATA WRAPPER %1$I;', foreign_data_wrapper_name) AS statements
FROM INFORMATION_SCHEMA.foreign_data_wrappers AS fdw
WHERE NOT EXISTS (SELECT 1
FROM INFORMATION_SCHEMA.foreign_servers AS fs
WHERE fdw.foreign_data_wrapper_name=fs.foreign_data_wrapper_name)
ORDER BY foreign_data_wrapper_name;
Drop the foreign data wrapper.

Collections

This query belongs to the following collections:

Find problems automatically

Queries, that results point to problems in the database. Each query in the collection produces an initial assessment. However, a human reviewer has the final say as to whether there is a problem or not .

NameDescription
Find problems automaticallyQueries, that results point to problems in the database. Each query in the collection produces an initial assessment. However, a human reviewer has the final say as to whether there is a problem or not .

Categories

This query is classified under the following categories:

Distributed database

Queries of this category provide information about the foreign table mechanism.

Unused implementation elements

Queries of this catergory provide information about the database objects that are not used.

NameDescription
Distributed databaseQueries of this category provide information about the foreign table mechanism.
Unused implementation elementsQueries of this catergory provide information about the database objects that are not used.