postGIS in Linux: dbf file can not be opened - postgresql

Downloaded file is unzipped. I moved it up the folder tree. I have the very latest version of LibreOffice in my Ubuntu. But I can't migrate the data therein to my postgis database. Have been working on this for some time any pointers appreciated. Linux output is below.
shp2pgsql -c -D -I tl_2019_us_cd116.shp gis.congress | psql -U sporter tutorial
Unable to open tl_2019_us_cd116.shp or tl_2019_us_cd116.SHP
tl_2019_us_cd116: dbf file (.dbf) can not be opened.
Per recommendations below I've been working on permissions but am stuck again. I'm logged in as root user on the path that has access to the file and as seen below it states ownership is being changed. But ls -l shows the original owner
root#DESKTOP-VDI7BFT:/mnt/c/Users/sport# chown -v sporter tl_2019_us_cd116
changed ownership of 'tl_2019_us_cd116' from sporter399 to sporter
But I don't think the ownership really changes:
ls -l tl_2019_us_cd116
-rwxrwxrwx 1 sporter399 sporter399 (7 times over for each file within the folder, all showing sporter399 which is what I'm trying to change)

Related

How to import a sample DB into postgres?

According to a website I can download their sample file dvdrental.zip, but
The database file is in zipformat ( dvdrental.zip) so you need to extract > it to dvdrental.tar
First of all, what is a tar? I thought it had to be tar.gz to be compressed? I don't even know how to create a "tar" by itself. I tried:
tar -zcvf dvdrental.tar.gz dvdrental
and
tar -cf dvdrental.tar dvdrental
I try to import with pgAdmin 4 and I get either:
pg_restore: [archiver] input file does not appear to be a valid archive
or
pg_restore: [tar archiver] could not find header for file "toc.dat" in tar archive
respectively. Now, don't ask me why a popular tutorial site created a file in the wrong format. But, can you tell me how to repackage this file so I can use it as a sample DB?
Using Mac OS 10.12.4. Postgres 9.6. And PgAdmin 4 (not sure if it's in beta? It crashed and does all kinds of nonsensical window movement and highlighting)
I have extracted .zip archive first. Then opened pgAdmin and followed the guide "Load the DVD Rental database using the pgAdmin"
https://www.postgresqltutorial.com/load-postgresql-sample-database/
Pay attention to changing 'Format' field from 'Custom or Tar' to 'Directory'. Then you should be able to restore DB.
If you look into the .tar archive you will find the restore.sql where at the top:
-- File paths need to be edited. Search for $$PATH$$ and
-- replace it with the path to the directory containing
-- the extracted data files.
So to create sample DB you could to extract .tar content somewhere and use single command:
sed -e 's/\$\$PATH\$\$/\/path\/to\/extracted\/files/g' restore.sql | psql
Or
sed -e 's/\$\$PATH\$\$/\/path\/to\/extracted\/files/g' restore.sql > r.sql
and try to execute the r.sql content using PgAdmin.
get sample dataset from the link you cited and save somewhere.
Assuming postgres is installed and running do the following:
Run createdb dvdrental
Run pg_restore -d dvdrental ./dvdrental where "./dvdrental" is the path to the downloaded and unzipped file.
For create sample DB in postgres you following this steps:
1.- Create directory and enter it:
mkdir -p /tmp/dvdrental && cd /tmp/dvdrental
2.- Download zip file dvdrental.zip:
wget https://www.postgresqltutorial.com/wp-content/uploads/2019/05/dvdrental.zip
3.- Uncompress file .zip and later .tar:
unzip dvdrental.zip
tar -xvf dvdrental.tar
4.- Replace in execution time $$PATH variable and review it with grep command:
sed -e 's/\$\$PATH\$\$/\/tmp\/dvdrental/g' restore.sql | grep --color dvdrental
5.- Import DB sample for specific host (localhost), port (5433), user (db) and database name (postgres):
sed -e 's/\$\$PATH\$\$/\/tmp\/dvdrental/g' restore.sql | psql -h localhost -p 5433 -U db -d postgres
Finally, I show import successful with program pgAdmin III

Option to exclude files in pg_basebackup command Postgres

When cloning a standby, how can I prevent pg_basebackup from copying postgresql.conf and pg_hba.conf from the master to /var/lib/pgsql/9.9/data directory?
Currently I am using this command
[root#xyz..]# pg_basebackup -h {master ipAddr} -D /var/lib/pgsql/9.6/data -U postgres -v -P
according to docs:
The backup will include all files in the data directory and
tablespaces, including the configuration files and any additional
files placed in the directory by third parties. But only regular files
and directories are copied. Symbolic links (other than those used for
tablespaces) and special device files are skipped.
So there is no such option. If you still want to force it, move config files away from data directory (and optionally ln them to data_dir)
This answer is for Postgres 14. pg_basebackup takes backup of the entire data directory. https://www.postgresql.org/docs/14/app-pgbasebackup.html states that the backup utility will skip all directory/file that are symbolic links. So, that could be a workaround to get only desired content into the tar ball.
I had faced similar situations where I wanted to exclude the content of multiple directories like pg_replslot,pg_dynshmem, pg_notify etc. I made the tar ball the usual way: pg_basebackup -D /backup/ -F t -P -v. After the tar ball was made, and before restoring it to another server, I updated the tar manually by excluding content of all the required directories.

Mongodump not stored in the specific location

I am doing a mongodump, and want to store it in a specific location. So, from reading online, I can do this using the following command:
sudo mongodump -d mydbs -u user -p password -o /myfolder/mongoBackups
I am using an EC2 instance, and when I run this command from my centos home folder, this is the output I get from mongodump:
2017-01-07T16:01:42.053+0000 writing mydbs.users to
2017-01-07T16:01:42.055+0000 done dumping mydbs.users (2 documents)
However, when I cannot find the folder myfolder/mongoBackups anywhere in the specific home/centos location where I run it. Any idea why?
It's not within home/centos
It's in /myfolder/mongoBackups
Specifying an output directory of /myfolder/mongoBackups is basically putting it in a folder called myfolder on the root of the hard drive.
If you truly want the folder to be within home/centos try
sudo mongodump -d mydbs -u user -p password -o /home/centos/myfolder/mongoBackups

pg_restore cant find the input file "X" no such directory or file

first off im relatively new to pgadmin and postgresql
so i have a backup done with pgadmin in plain text which dumps the data i need from one table into a file called lodging. it came from a plans_to_lodge table from our live server. now to test a new web application front end i want to pg_restore it but this is what i get
> pg_restore -h localhost -d TestingDatabase2 -t lodging_of_plans -n plan_authentication "C:\lodging"
pg_restore: [archiver] could not open input file "C:\lodging": No such file or directory
the documentation doesnt give an example for a table restore
and yes the file is at that location in the C drive
The issue was it being the root folder, so when i put the file named lodging into another folder like so
C:\folder\lodging
it worked now onto more errors

pgrouting error when trying to dump data into database

I was just following this tutorial HERE, its about, pgrouting, When I run the following command:
psql -U user -d postgres -f ~/Desktop/pgrouting-workshop/data/sampledata_routing.sql
I get an error saying the following:
/var/lib/postgresql/Desktop/pgrouting-workshop/data/sampledata_routing.sql: No such file or directory
On my desktop I do have a folder pgrouting-workshop, which does contain the folder data and the sql dump file.
So why am I getting this error?
Because your Desktop isn't in the postgres user's home directory, located at /var/lib/postgresql, but is instead located at /home/myusername/Desktop?
Presumably the psql command you're running is under a sudo -u postgres -i shell, so ~/ means the postgres user's home directory.
Use ~myusername/Desktop/blahblah. Note that the postgres user may not have permission to access it; you can chmod go+x ~ ~/Desktop (run as your user, not postgres) to change that.