-- Firstly, remove PRIMARY KEY attribute of former PRIMARY KEY
ALTER TABLE <table_name> DROP CONSTRAINT <table_name>_pkey;-- Then change column name of your PRIMARY KEY and PRIMARY KEY candidates properly.
ALTER TABLE <table_name> RENAME COLUMN <primary_key_candidate> TO id;-- Lastly set your new PRIMARY KEY
ALTER TABLE <table_name> ADD PRIMARY KEY (id);
It's important to note that if the primary key is used as a foreign key constraint in other tables, you'll have to include the keyword
CASCADEat the end of theDROP CONSTRAINTcommand. Subsequently, you will also need to individually recreate the foreign keys in the other tables.