dropped geometry_columns and geography_columns tables - postgresql

(cross-posted from https://gis.stackexchange.com/q/320977/104667)
I've accidentally dropped geometry_columns and geography_columns tables from an existing PostgreSQL PostGIS database schema - let's call it mydb.myschema.
This post outlines how to restore using CREATE TABLE ... with .sql from PostGIS install (I am on a shared server and am having to get my devops to look for them because of permissions).
I wanted to check if this will work. Also, do these two tables (geometry_columns and geography_columns) contain data relating to the geometries held in existing tables in mydb.myschema. Or do geometry_columns and geography_columns hold reference information for spatial operations?
Advice from anyone who has gone through this before welcome.
Running Postgis 2.5.2 ON pg 11.x.
[NOTE: No backup available as snapshots weren't set up beforehand...]

Related

Is there a way to link (not import!) a dbf table into a PostgreSQL database?

I need to link an external dbf table into an existing PostgreSQL database. I managed to import that table into PostgreSQL but that creates a copy and therefor redundant data. The dbf table is the attribute table of a shapefile, but I don’t need the spatial aspect of it.
The exercise is part of a project to move data from an MS Access database to PostgreSQL hoping that the data then become accessible from QGIS. Th dbf table is at the moment linked into the MS Access database and used in queries (views) which I want to re-build in PostgreSQL.
I found lots of posts about importing dbf tables into but nothing which would work about linking a dbf table. The closest I got was the Foreign Data Wrapper, but I didn’t manage to use it for my purpose. I’m using PostgreSQL with pgAdmin 4.24.
Many thanks
The exercise is part of a project to move data from an MS Access database to PostgreSQL hoping that the data then become accessible from QGIS.
If you must use PostgreSQL in order to provide access to your spatial data from QGIS, I see no other option than importing the shapefile into PostgreSQL (PostGIS). If for whatever reason you do not need the geometries, you can drop the geometry column after importing the shapefile into the database:
ALTER TABLE table_name DROP COLUMN column_name;
Alternative scenario:
If we're talking about static shapefiles and you don't really need to use PostgreSQL, you can use GeoServer to publish this shapefile via Web Feature Service (WFS) - it is at least what I do in small projects. The easiest option would be to copy the shapefiles into a so called GeoServer Data Directory and publish them afterwards. After that you'd be able to access the data from QGIS using its WFS Client.

How to replicate rows into different tables of different database in postgresql?

I use postgresql. I have many databases in a server. There is one database which I use the most say 'main'. This 'main' has many tables inside it. And also other databases have many tables inside them.
What I want to do is, whenever a new row is inserted into 'main.users' table I wish to insert the same data into 'users' table of other databases. How shall I do it in postgresql? Similarly I wish to do the same for all actions like UPDATE, DELETE etc.,
I had gone through the "logical replication" concept as suggested by you. In my case I know the source db name up front and I will come to know the target db name as part of the query. So it is going to be dynamic.
How to achieve this? is there any db concept available in postgresql? Or I welcome all other possible ways as well. Please share me some idea on this.
If this is all on the same Postgres instance (aka "cluster"), then I would recommend to use a foreign table to access the tables from the "main" database in the other databases.
Those foreign tables look like "local" tables inside each database, but access the original data in the source database directly, so there is no need to synchronize anything.
Upgrade to a recent PostgreSQL release and use logical replication.
Add a trigger on the table in the master database that uses dblink to access and write the other databases.
Be sure to consider what should be done if the row alreasdy exists remotely, or if the rome server is unreachable.
Also not that updates propogated usign dblink are not rolled back if the inboking transaction is rolled back

Postgresql database size is less after migration from oracle

I have migrated Oracle to Postgresql using Ora2pg tool.
The database size before migration in Oracle is around 2Tb,
The same database after migration into Postgresql,size seems only 600 gb.
NOTE: Records are migrated correctly with equal row counts.
Also i wanted to know how Postgresql handles Bytea data type after migration from Blob in oracle.
You might want to check if all migrated objects are present.
However, this is not surprising, and there are several things that can contribute to that:
You counted the size of the tablespaces in Oracle, but they were partly empty.
Your table and index blocks were fragmented, while they are not in the newly imported PostgreSQL database.
Depending on which options you installed in Oracle, the data dictionary can be quite large (though that alone cannot explain the observed difference).

Importing data from MS Access db to PostgreSQL db

I have a table in an MS Access db that I want to export to a PostgreSQL database. Every 2 or so months, I want to move all records from the Access table to a table in Postgres.
Right now, I am using the Export to ODBC option in Access to do this, but every time it exports as an entirely new table in Postgres. Is there a way for me to routinely append the records in the Access table to an existing table in my Postgres database? I have come across the option of a FDW but I am not familiar with how to install/use it.
I am new to using PostgreSQL, and have little to no experience working with databases other than Access, so any input/advice would be greatly appreciated.

PostGIS vs Postgresql Performance in normal tables

i have a question that i couldn't find an answer for searching in my own, and i thank you for your help in advance.
Is it better to create the non spatial tables & relations in PostGIS Database with spatial tables, or To create special tables in PostGIS and create non spatial tables & relations in normal PostgreSQL database, and if the we go with the latter choice how to properly do it?