PostGIS & QGIS - PostGIS extension not accessible? - postgresql

I am having an odd problem with PostGreSQL/PostGIS on a Windows 10 machine.
I have successfully installed PostGIS many times without issue over the years, most recently last week on a Windows 10 machine at work. I typically use QGIS as my client, so have a fair idea how these things need to be configured and operated.
Over the weekend, I downloaded the latest PostGres 11 installer with Stackbuilder, and installed PostGres & PostGIS. pgAdmin4 seems to show everything is as it should be, and the sample 'postgis_23_sample' database is present and correct.
However, using QGIS DB Manager, when I try to connect to the database (on port 5432), whilst I can see the sample database and public schema, I cannot create a new table with geometry, or load any data (e.g. a simple shapefile) into the database. The error message tells me that the 'addGeometryColumn' function does not exist. I checked that the PostGIS extension is installed - which it is. (I ran 'CREATE EXTENSION postgis' again to confirm this.)
So, I went back to pgAdmin, and tried creating a table with geometry via SQL, but got the same error: Creating a table without geometry works just fine. As soon as I try to create a geometry column, I get the error. It seems to me that the PostGIS extension is somehow not being 'found' by PostGres.
I have uninstalled and reinstalled various combinations of PostGres, PostGIS and QGIS over the weekend - but get the same error. I created a new Windows account, and tried installing the stack there: same thing happened.
I also tried uninstalling everything and then installing the 'Portable GIS' stack by Astun. These are much older versions of QGIS and PostGIS, but in theory the installer configures them all to work together. (That, at least, has been my past experience of using Portable GIS at work.) In this instance, I got the same error about the missing AddGeometryColumn function.
I am wondering if the various installs of PostGIS, QGIS and other tools over the last year or so have left some stubborn configuration entries (maybe in the registry?) that uninstallers have not been able to remove. Could something like that be upsetting my recent PostGres insatllations? It feels as though something is preventing DB clients from locating the PostGIS services on the assigned port. Having said that, PostGres iteslef seems to be working fine, so maybe that is nonsense.
In any case, if anyone has any ideas how I can begin to debug and fix this, I would be hugely grateful. (In the meantime, I am about to try the OSGeoLive Lubuntu VM, which at least will enable me to get some proper work done - I hope.)
Thank you...

Related

Upgraded pgAdmin shows warning, not displaying Tables list, queries working without problem

I upgraded my local Postgresql test server to PostgreSQL15 today morning.
Opening pgAdmin gave me a warning that some of the features may not work correctly because I have a server with version 9 added to pgAdmin.
Steps done:
Upgraded Postgresql v14 to v15.
PgAdmin shows warnings and couldn't see the tables list.
Uninstalled v15 and installed v14. Again the same issue.
Uninstalled v14 and get v12 of Postgresql.
Clean uninstall was done by removing the Postgresql folder from the "ProgamFiles" folder and "AppData/Roaming"
Current situation:
Still, pgAdmin is not showing the list of tables for the older server version (v9).
I cannot upgrade this server, but have to use it in PgAdmin as before.
But I can run the all queries without any problem.
When adding the V9 server, pgAdmin shows a warning like this
It is listing up all schemas, views, and sequences. But when clicking the Tables, it keeps loading and never gives the list of tables.
By the way, I am using Windows 10 64bit OS.
After five days, I degraded my Postgresql to V12 and now getting an error like this:
ERROR: column "wait_event_type" does not exist LINE 10: wait_event_type || ': ' || wait_event AS wait_event, ^
enter code here
Have anybody gone through such an issue? Need some help. Thanks in advance.

Import/Export Dialog Disappeared in pgAdmin

I use a PostgreSQL database on my local computer. I always import csv files via right-click to the relevant table and choosing the Import/Export Dialog. However, when I opened the pgadmin last time, there was no import/export option in the options. I do not know what happened to it. I, once, took a backup of files and use this backup file to migrate the database to another version of Postgres. I am not sure but I want to ask might one of the options that I selected or did not select cause this trouble?
I also tried to go in an alternative way by using copy from 'C://path/data.csv method and it did not work. then I tried \copy from 'C://path/data.csv but it did not even recognize the \ symbol and gave an error.
I wonder what happened to Postgres or pgadmin and how can I find a solution to import my data to the Postgres database?
I had the same issue, looked everywhere but nothing came up on WHY this happened or HOW to fix it.
RESOLUTION: I was able to resolve this by downloading the latest version of pgadmin4.
After downloading, the Import/Export dialog reappeared.
Hope this helps you too!
Import/Export Dialog - Resolved

Connect PostgreSQL to HammerDB

As the title says, I want to connect PostgreSQL (I'm using the 9.6 x86 version) to HammerDB, an open source database load testing and benchmarking tool (I'm interested in the TPC-C Benchmark).
The thing is that I can do this connection by using MS SQL Server (2014), because it is relatively easy. However, I'm not used to use PostgreSQL. When I try to create Virtual Users on HammerDB (that's the 1st step to do, then you should be able to perform the transactions) I get the following error:
Error in Virtual User 1: Failed to load Pgtcl - Postgres Library Error
I did some research about this, and I found that, and I quote "PostgreSQL is VERY particular about the libraries in its PATH - they have to be the right ones and ONLY the right ones any other configuration will cause errors".
The problem is that HammerDB couldn't load library libpgtcl.dll. There they mention that to fix the problem, one should check that the PostgreSQL bin directory has been added to the path during install, but at this point I'm totally lost and I don't know what to do. I simply canĀ“t get what they mean and how to do it.
I hope at least one of you could help me. I would appreciate it a lot.
Sorry in advance for my mistakes in English, I'm a Spanish speaker.
Well, I have solved the problem, and it is very simple.
Everything is about Setting Windows PATH for PostgreSQL, and I found that here.
Open my Computer ==>
right click inside my computer and select properties ==>
Click on Advanced System Settings ==>
Environment Variables ==>
from the System Variables box select "PATH" ==>
Edit... ==>
Then add this at the end of whatever you find their
;C:\PostgreSQL\9.2\bin; C:\PostgreSQL\9.2\lib
after that continue to click OK
That's all. So this is what you should do if you are having trouble when trying to connect PostgreSQL to HammerDB, and in general, when trying to use PostgreSQL tools.

flyway 3.3 migrations with postgresql and postgis extension

I am at my wits end, and I don't what else I can try. I am trying to do a flyway clean on my local database. I have Postgres 9.4 latest with latest PostGIS extension. I am using the public schema to store 10 tables, and 7 sequences ... it's very small.
Now I am trying to do a simple FlywayDB 3.3 clean instruction with maven. I have the username and password and public schema listed in the maven configuration file. I constantly kept getting errors to suggest various views and tables are used by the PostGIS extension, so it won't delete them.
So, a search here, and on the Internet in general suggested I do:
ALTER USER myuser WITH SUPERUSER; This did not solve my problems.
In other research, it was suggested to use another schema for data, and not the public schema. So, I created a new schema for my app, and moved over my sequences and tables, including table spatial_ref_sys. I updated the maven config to clean only this new schema ... but it says it cannot delete "spatial_ref_sys" because it is used by PostGIS.
I have 10 tables uses for my app, with 7 sequences ... I just want Flyway to clean my database, so I can try the baseline file to rebuild it. I am no expert in PostGIS, so I don't know if I can remnove that table without killing any spatial functionality I want to use in the future.
Thanks for any help, and please let me know if I can provide any other data.
This is a known issue with no trivial solution but 2 good workarounds: https://github.com/flyway/flyway/issues/100
As noted it's a known issue with flyway.
adding a file called beforeClean.sql with the statement:
DROP EXTENSION IF EXISTS PostGIS;
Solves the problem

Eclipse plugin for psql/PostgreSQL code?

Do you have recommendations for a good PostgreSQL editor plugin for Eclipse?
The PostgreSQL code I have isn't very complex. However I'd like to edit it with syntax-coloring, decent auto-identation, code completion, etc., and it would be sweet to be able to send blocks or entire files to a jdbc connection and get the results. Up until now, I have edited my .sql files with Emacs, and try things by copying/pasting segments into a psql terminal I have next to Emacs. Some of my code uses the psql primitives such as \set var value etc. For example:
\set t mytable
drop table if exists :t;
create table :t (...);
However I would be happy to eliminate this and refactor the code to be proper PL/pgSQL functions. Or perhaps better, implement the dependency and procedural logic in Java and issue the sql queries via JDBC. I still need to edit the sql files and try bits and pieces of them during development.
I tried the "official" Data Tools Platform (http://eclipse.org/datatools/) and configured it to use my localhost:5432 (which in fact is a port-forward via SSH to the actual PostgreSQL server that I'm using). However, connecting to the DB hangs for several minutes (Eclipse doesn't even refresh the screen). In general it feels quite heavy/slow
and I'm always afraid of if hanging without ability to interrupt it (it happened a few times and the only solution is to kill Eclipse; as you probably know, killing Eclipse isn't good as it's very hard/impossible to recover unsaved files).
The other plugin I tried is Toby's PL/SQL editor (https://sourceforge.net/projects/plsqleditor/), which seems very nice and promising, except the last signs of life on the sourceforge forums appear to be around 2007. Also I couldn't configure it to use the postgresql-9.0-801.jdbc4.jar that I have, and so I am unable to connect to my DB.
Any suggestions gladly appreciated.
A free Eclipse plugin for Oracle and PostgreSQL can be found at http://www.toadworld.com/products/toad-extension-for-eclipse/default.aspx
The plugin is in development.