EDUCBA Logo

EDUCBA

MENUMENU
  • Explore
    • EDUCBA Pro
    • PRO Bundles
    • Featured Skills
    • New & Trending
    • Fresh Entries
    • Finance
    • Data Science
    • Programming and Dev
    • Excel
    • Marketing
    • HR
    • PDP
    • VFX and Design
    • Project Management
    • Exam Prep
    • All Courses
  • Blog
  • Enterprise
  • Free Courses
  • Log in
  • Sign Up
Home Data Science Data Science Tutorials PostgreSQL Tutorial PostgreSQL DROP INDEX
 

PostgreSQL DROP INDEX

Priya Pedamkar
Article byPriya Pedamkar

Updated May 12, 2023

PostgreSQL DROP INDEX

 

 

Definition of PostgreSQL DROP INDEX

PostgreSQL drop index statement is used to drop or delete the existing index from a table column; we have used the drop index command to drop the existing index in PostgreSQL. To use the drop index command, we need to have superuser privileges or need to have the owner of that specific index. If the object depends on the index, then the index is not dropped error will be given that the index will not drop; basically, cascade operations with concurrent are not supported in the PostgreSQL drop index command. Drop index command is very useful and important in PostgreSQL to drop the unused index.

Watch our Demo Courses and Videos

Valuation, Hadoop, Excel, Mobile Apps, Web Development & many more.

Syntax and Parameter

Below is the syntax of the drop index statement in PostgreSQL.

  • Drop index index_name; — Name of the index we dropped using the drop index command.
  • Drop index index_name1, index_name2, index_name3, …., index_nameN.
  • Drop index [Concurrently (Drop index without affecting or locking other operations like select, insert, update, and delete)] [if exists (Drop the index if it exists in the database also do not throw the error if the index in not exist)] name_of_index (Name of the index which was we have dropping) [Cascade | Restrict ]

Parameter:

Below is the parameter description syntax of the drop index statement.

  • Drop index: You can use this command to drop the existing index and remove the unused index from the database table column in PostgreSQL.
  • Index name: We define the index name we want to drop from the database table.
  • Concurrently: Drop the index without affecting the other operations like select, insert, update, and delete. Drop index in PostgreSQL will acquire the exclusive lock on the table; it will block operations access until the drop index was not completed successfully. After using concurrent options with the drop index command, it is not possible to perform cascade operations.
  • If it exists: This option is used when the index is not present on the database table; after using these options, it will not show the error of the index cannot exist. The index will issue a notice if it is not on the database table.
  • Cascade: We use this option to drop the index object that depends on the index automatically. But cascade options are not supported with concurrent options in PostgreSQL.
  • Restrict: It is used when we do not have to use the drop index option on an index forcefully. It will refuse the drop index command when any other object depends on that index. This is a default parameter of the drop index command.

How to DROP INDEX Statement Work in PostgreSQL?

  • Below is the working of the drop index statement in PostgreSQL.
  • The index will increase the performance of select operations from the table. But it will degrade the performance of insert and update operations.
  • If our database table contains the insert and update operations more than select, then we need to delete the same index from the table at that time, we have using the drop index statement to drop unused index from the database.
  • We need a superuser or owner of index privileges to drop the index from the database table.
  • The example below shows that we need a superuser or owner of index privileges to drop the index.
psql -U index_test -d testing
drop index index_test;
psql -U postgres -d testing
drop index index_test;

PostgreSQL DROP INDEX-1.1

  • In the above first example, we have used the user index_test to drop the index name as index_test from the student table. But it will throw the error of “ERROR: must be the owner of the relation index_test”.
  • In the second example, we have used the superuser of the database, i.e., Postgres; using the superuser, it is possible to drop the index in PostgreSQL.
  • We can drop multiple indexes in a single statement using the drop index command in PostgreSQL.
  • If the object depends on the index, the same index will not dropped using the drop index operations.
  • The below example shows that if any object depends on the index, it will not be dropped.
drop index student_pkey;

PostgreSQL DROP INDEX-1.2

  • In the above example, we have to try to drop the index of student_pkey, but it will not be dropped because other objects depend on this index.
  • It will show the error of “ERROR: cannot drop index student_pkey because constraint student_pkey on table student requires it”.

Examples of PostgreSQL DROP INDEX

Below is an example of the drop index command in PostgreSQL.

1. Drop single Index Using Drop Index Command

In the below example, we have dropped a single index using the drop index command. In the below example, we have drop the index name as index_test from the student table.

\d+ student
drop index "index_test";
\d+ student

PostgreSQL DROP INDEX-1.3

2. Drop Multiple Index Using the Drop Index Command

In the below example, we have dropped multiple indexes using the drop index command. In the example below, we have dropped the index names p_index and n_index from the student table.

\d+ student
drop index p_index, n_index;
\d+ student

Output-1.4

3. Drop the Index Using the if Exists Parameter

In the below example, we have used if exists a parameter with the drop index command. If exists parameter will skip the index.

\d+ student
drop index IF EXISTS p_index;

Output-1.5

4. Drop Index Using Concurrently Parameter

In the below example, we have used the parameter concurrently with the drop index command. We have drop the c_index from the student table.

\d+ student
drop index concurrently "c_index";
\d+ student

Output-1.6

Recommended Articles

We hope that this EDUCBA information on “PostgreSQL DROP INDEX” was beneficial to you. You can view EDUCBA’s recommended articles for more information.

  1. PostgreSQL Materialized Views
  2. PostgreSQL UNIQUE Index
  3. Vacuum PostgreSQL
  4. REINDEX PostgreSQL

Primary Sidebar

Footer

Follow us!
  • EDUCBA FacebookEDUCBA TwitterEDUCBA LinkedINEDUCBA Instagram
  • EDUCBA YoutubeEDUCBA CourseraEDUCBA Udemy
APPS
EDUCBA Android AppEDUCBA iOS App
Blog
  • Blog
  • Free Tutorials
  • About us
  • Contact us
  • Log in
Courses
  • Enterprise Solutions
  • Free Courses
  • Explore Programs
  • All Courses
  • All in One Bundles
  • Sign up
Email
  • [email protected]

ISO 10004:2018 & ISO 9001:2015 Certified

© 2025 - EDUCBA. ALL RIGHTS RESERVED. THE CERTIFICATION NAMES ARE THE TRADEMARKS OF THEIR RESPECTIVE OWNERS.

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you
Loading . . .
Quiz
Question:

Answer:

Quiz Result
Total QuestionsCorrect AnswersWrong AnswersPercentage

Explore 1000+ varieties of Mock tests View more

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA
Free Data Science Course

Hadoop, Data Science, Statistics & others

By continuing above step, you agree to our Terms of Use and Privacy Policy.
*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you

EDUCBA Login

Forgot Password?

🚀 Limited Time Offer! - 🎁 ENROLL NOW