I’m trying to CREATE TABLE command in Postgresql.
After creating a table, if I punch in TABLE table name, it works.
But I punch in \d table name, I keep getting an error below.
ERROR: column c.relhasoids does not exist
LINE 1: ...riggers, c.relrowsecurity, c.relforcerowsecurity, c.relhasoi...
I attempted DROP DATABASE table name recreated a database and recreated a table again several times. But it didn't work.
Any suggestions would be appreciated! Thank you.
I am able to reproduce your error if I am using Postgres v.12 and an older client (v.11 or earlier):
[root#def /]# psql -h 172.17.0.3
psql (11.5, server 12.0)
WARNING: psql major version 11, server major version 12.
Some psql features might not work.
Type "help" for help.
postgres=# create table mytable (id int, name text);
CREATE TABLE
postgres=# table mytable;
id | name
----+------
(0 rows)
postgres=# \d mytable;
ERROR: column c.relhasoids does not exist
LINE 1: ...riggers, c.relrowsecurity, c.relforcerowsecurity, c.relhasoi...
^
postgres=#
This is because in v. 12, table OIDs are no longer treated as special columns, and hence the relhasoids column is no longer necessary. Please make sure you're using a v. 12 psql binary so you don't encounter this error.
You may not necessarily be using psql, so the more general answer here is to make sure you’re using a compatible client.
For anyone running Postgres as a Docker container:
Instead of running psql from the host, run it from inside the container e.g.
docker exec -it postgres_container_name psql your_connection_string
The Postgres image always ships with the corresponding—and thus always updated—version of psql so you don't have to worry about having the correct version installed on the host machine.
If you're using DataGrip, there's an easy fix:
Try using "Introspect using JDBC metadata". This fixed it for me when (I think) I had a version mismatch between postgresql server and DataGrip client.
Under your connection settings -> Options tab -> check Introspect using JDBC metadata
According to https://www.jetbrains.com/help/datagrip/data-sources-and-drivers-dialog.html#optionsTab :
Switch to the JDBC-based introspector.
To retrieve information about database objects (DB metadata), DataGrip
uses the following introspectors:
A native introspector (might be unavailable for certain DBMS). The
native introspector uses DBMS-specific tables and views as a source of
metadata. It can retrieve DBMS-specific details and produce a more
precise picture of database objects.
A JDBC-based introspector (available for all the DBMS). The JDBC-based
introspector uses the metadata provided by the JDBC driver. It can
retrieve only standard information about database objects and their
properties.
Consider using the JDBC-based intorspector when the native
introspector fails or is not available.
The native introspector can fail, when your database server version is
older than the minimum version supported by DataGrip.
You can try to switch to the JDBC-based introspector to fix problems
with retrieving the database structure information from your database.
For example, when the schemas that exist in your database or database
objects below the schema level are not shown in the Database tool
window.
The issue is the client (psql) is a different version from the postgres server. I have seen this issue with psql version 11 talking to postgres version 12. To solve this issue upgrade the psql version to 12.
If you are running a docker postgres, you can exec into the container then use the psql client installed there.
# get the container id with this
docker ps
# Then exec into the container, please note the host will now be 120.0.0.1
docker exec -it c12e8c6b8eb5 /bin/bash
I had this issue because my psql was 9.2 and the server version was 12.7.
So ... clearly the psql client needs to be updated. But how?
Before you go downloading/installing anything though you may already have the right version. In my case I did.
I executed which psql which showed my version was coming from /usr/bin/psql.
I then checked /usr/pgsql-12/bin and found there was a psql in there.
So all I needed to do was ensure psql was picked up from there.
There are a number of places that could be controlling this; in my case I just added this line to my .pgsql_profile (in the postgres user's home directory):
export PATH="/usr/pgsql-12/bin:$PATH"
Logging out and back in as postgres and executing which psql showed the change had been successful:
which psql
/usr/pgsql-12/bin/psql
This answer is specific to pgcli
If you are using pgcli you may be encountering this issue. It's solved by updating the python package pgspecial.
If you installed pgcli using pip, you can simply do, depending on your python version:
pip install -U pgspecial
or
pip3 install -U pgspecial
If you are using Ubuntu and intalled pgcli using apt, you can either switch it to pip with:
sudo apt remove --purge pgcli
pip3 install pgcli
or update the distribution package python-pgspecial or python3-pgspecial from the Ubuntu packages web site. In that case you may need to update its dependencies as well.
I had this issue today, was unable to continue work due to this, strangely the application code is working fine.
Later, found this issue is only occurring if I use OmniDb client I use to connect to DB.
I have switched client to default pgAdmin 4 that comes with postgres installation & issue is not occurring anymore pgAdmin 4. Link: https://www.pgadmin.org/download/pgadmin-4-windows/
Its possible that OmniDb client might be older, but no time to troubleshoot it, using pgAdmin 4 for now.
Hope that helps.
Just update DataGrip solved this issue, Datagrip updated to version DataGrip 2019.3.3, Build #DB-193.6494.42, built on February 12, 2020, Now working :)
Just for DataGrip users!
I had the same issue today too. In my case, the problem was solved when I deleted the version 12 and installed the version 11. Seems that v12 has some features that must be create along the others columns.
I had the same problem.
But I found the solution by downloading the latest build on 14/10/2019
Follow the link:
https://postbird.paxa.kuber.host/2019_10_14.06_42-master-7a9e949
I hope it helps
To fix this, edit Postgres.php file and comment the lines from hasObjectID function as shown below.
function hasObjectID($table) {
$c_schema = $this->_schema;
$this->clean($c_schema);
$this->clean($table);
/*
$sql = "SELECT relhasoids FROM pg_catalog.pg_class WHERE relname='{$table}'
AND relnamespace = (SELECT oid FROM pg_catalog.pg_namespace WHERE nspname='{$c_schema}')";
$rs = $this->selectSet($sql);
if ($rs->recordCount() != 1) return null;
else {
$rs->fields['relhasoids'] = $this->phpBool($rs->fields['relhasoids']);
return $rs->fields['relhasoids'];
}
*/
}
I had the same issue when using PgAdmin to query the database.
Once I installed the newest version of PgAdmin the error disappeared!
You might also try restarting pgadmin.
After upgrading from postgres96 to postgres12 I had the same issue. My pgadmin was running psql v12.0 so that wasn't the issue. I restarted pgadmin for a separate issue and the relhasoids issue went away.
If anyone could explain to me why this worked that would be appreciated.
Just use version 11.
how to install version 11
https://websiteforstudents.com/how-to-install-postgresql-11-on-ubuntu-16-04-18-04-servers/
I also got same issue with my postgresql tables. I have fixed this issue by below query.
ALTER Table MyDataBase.table_name add column column_name data_type default 0 not null;
commit;
I had Postgresql 9.6 installed (on Windows 10) and did a complete uninstall including the data directory and all old copies of PgAdmin and there are no environment variables relating to this or any other old Postgres installation either.
I recently installed Postgresql 11 and PgAdmin 4 v3.6 using EnterpriseDB installer. When I run PgAdmin 4 it aurto detects a postgresql instance called 9.6 - though the details tell me it is actually my v11 instance with the same port number and password etc. The only difference is that it is pointing to the non-existent old data directory.
I have searched for a stray postgresql.conf file (and can't find one as it was in the deleted data directory!). As there is also no environment variables, no binaries and no data I can't understand how PgAdmin is auto detecting this ghost. Any suggestions on how to correct it?
EDIT:
I have tried deleting all cookies relating to PgAdmin and Postgresql in Chrome too - this had no effect
I have also double checked that there is no postgresql 9.6 service running (but that just confirms the above where PgAdmin tells me it is called 9.6 but actually is a v11 instance)
Try deleting pgAdmin4 config file pgadmin4.db located at %APPDATA%\pgAdmin\
Restart pgAdmin4 and check.
I need to use the new jsonb field in postgres so I decided to upgrade to 9.5 in my ununtu 16.04 LTS. I followed this tutorial , but when it gets to the command pg_upgradecluster 9.3 main, I get the error that cluster configuration already exists. I checked other tutorials and found that I could get the list of clusters with pg_lsclusters. But the command always shows only the 9.3 cluster. Any attempt to create the 9.5 cluster always results to cluster configuration already exists. I purged the 9.5 and installed again multiple times but the same result. At last I decided to purge all the postgres installations I have after backing up my 9.3 cluster with pg_dumpall.
Now I have decided to install the 9.5 freshly but I still get the same thing. When I install pg_lsclusters shows nothing and after starting postgres psql always returns psql: could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?
Right now I'm so tired and frustrated. Please if anyone has any possible solution or suggestion, help
The problem seemed to be from the version 9.5 in the postgres repositories. I installed 9.6 and everything worked like magic. Had I known there was a stable 9.6 earlier, I wouldn't have wasted 6 hours of my life in something I could have done for 10 minutes. Anyway, I'm happy I have have a working postgres with jsonb field
I have upgraded from 9.2 to 9.3 successfully on ubuntu. However,
/etc/init.d/postgresql start
starts both 9.2 and 9.3
Although the above command can accept that the version number and successfully starts and stops each one, is there any method I can use to make this command start 9.3 only.
The reason is that, I am not able to reboot the system now, but I am afraid when it is rebooted both servers can start.
My short term solution is to adjust the port numbers to make my application use 9.3 database. However, I would like to learn about more permanent and robust solutions.
Thanks in advance,
Steve
Ubuntu uses pg_wrapper to manage PostgreSQL installs. See the Ubuntu PostgreSQL wiki page.
You'll want to pg_dropcluster the 9.2 cluster, if you wish to actually destroy the old data. Or un-install PostgreSQL 9.2. Or modify the config file (don't remember the name right now) in /etc/postgresql/9.2/ that controls whether Pg starts or not. It's called something like start.conf or pg_ctl.conf or something.
You may also want to reverse the configured ports so your new 9.3 runs on 5432 and your not-started-by-default 9.2 tuns on 5433. That is in postgresql.conf.
Steve Harman's response worked perfectly for me, too:
Thanks for the response. In the /etc/postgresql/9.2/main/ directory, there is start.conf. If you change the single line in that file from 'auto' to 'disabled' then, /etc/init.d/postgresql start will not start 9.2. – Steve Harman Jan 1 at 16:55
On the other hand, just fyi, the command output is that both versions of the server are starting (which is not true and is coming from the service starting scripts)
user#server:/etc/postgresql/9.3/main$ sudo service postgresql start
* Starting PostgreSQL 9.1 database server
...done.
* Starting PostgreSQL 9.3 database server
...done.
I was working with postgresql, and suddenly, this stop it. I stoped service, but when i try start it, never i can do it.
service postgresql start FAIL
don't have a backup, and with pg_dump is imposible.
pg_dump -i -h localhost -p 5432 -U postgres -F c -b -v -f "/mibase.backup" mydatabase
which is the best form to do a backup?
I had a lot of trouble with PostgreSQL 9.0.2 under Windows. The service would just stop every couple of days. I never had trouble restarting it, though. Never had to restart the Windows server to restart the PostgreSQL service.
With the PostgreSQL service shut down, you can copy the database files.
If you're not on the most current release of your version, you might try installing a more recent minor version. Postgresql doesn't mind running multiple versions on the same server, although they each have to listen on a different port.
The minor version number is the third digit. Above, the major version is "9.0". If you're running 9.0.2, you want 9.0.[a number greater than 2]. Why?
"Minor releases never change the internal storage format and are always compatible with earlier and later minor releases of the same major version number, e.g., 8.4.2 is compatible with 8.4, 8.4.1 and 8.4.6." (Upgrading a PostgreSQL Cluster)
So a minor version upgrade, listening on a different port, and pointing to your old data directory might let you make a SQL dump. A SQL dump can be restored to any version.
A minor version upgrade pointing to a new data directory should be able to read files copied at the filesystem level. (Paragraph 2, way above.)