about hawq pxf access file data on hdfs - postgresql

After I deployed hdfs, map reduce, hawq, pxf with ambari, I have generated about 10G data on hdfs using impala-tpcds-kits.
But when I login in Postgres with the user postgres, I can't use the command line CREATE EXTERNAL TABLE to index the data on hdfs. And when I use psql help command, there isn't the key word CREATE EXTERNAL TABLE.
I don't know why?
Last login: Thu Aug 25 15:08:15 2016 from 192.168.1.50
[root#hadoop-m-21 ~]# su postgres
bash-4.1$ psql
psql (8.4.20)
Type "help" for help.
postgres=# CREATE EXTERNAL TABLE EXT_LOG_INFO (hight int,weight int)
LOCATION ('pxf://10.0.0.21:51200/tmp/test2.txt?PROFILE=HdfsTextSimple')
FORMAT 'TEXT' (DELIMITER '|');
ERROR: syntax error at or near "EXTERNAL"
LINE 1: CREATE EXTERNAL TABLE EXT_LOG_INFO (hight int,weight int) LO...
^

You aren't connecting to HAWQ.
[root#hadoop-m-21 ~]# su postgres
bash-4.1$ psql
psql (8.4.20)
Type "help" for help.
This is a PostgreSQL database and likely the database installed for Ambari. Use the gpadmin account instead of postgres.
Also, if you are wanting to run TPC-DS, try this one instead which is designed for HAWQ and Greenplum. https://github.com/pivotalguru/TPC-DS

Please make sure you are calling psql which connect to hawq, instead of connecting to linux built-in postgreSQL instance.
You can run 'netstat -anp | grep 5432' to know the pid of postgres, and use 'ps -ef | grep your_pid to know the binary path, check the path is hawq.
Or you can run SQL 'SELECT VERSION();' in psql to check.

You might be connecting to ambari postgres. Check hawq settings in Ambari and use
psql -h hostname -p port -d database -U username.

Please follow the below steps .
Login to hawq master node
ps -ef |grep silent (Find out the port that hawq master is listening to )
su - gpadmin
psql ( psql should connect you to hawq gpadmin database )
if not type
psql -p portnumber -h masterhost -d database

Related

How can connect psql with normal user without specifying database name?

I can connect mysql with username without specifying any database name,showkey is one of mysql user:
mysql -u showkey -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 14
Server version: 10.3.31-MariaDB-0+deb10u1 Debian 10
Now i log into mysql without specifying any database name.showkey is also a normal user for my postgresql,test is a database name in my postgresql.
psql -d test -U showkey
Timing is on.
Pager usage is off.
Null display is "missing data".
psql (11.14 (Debian 11.14-0+deb10u1))
Type "help" for help.
test=#
I conncet the test database with a normal user showkey,now want to connect postgresql with normal user without specifying database name such way as in mysql:
psql -U showkey
psql: FATAL: database "showkey" does not exist
sudo -u postgres psql can connect postgresql with a super user instead of with normal user.

executing a .sql file through ubuntu command line for postgres

I have installed postgresql on ubuntu using:
$ sudo apt install postgresql
Now, I have a series of sql queries I would like to fire to create schemas and users and tables etc. I have put those queries in a .sql file as below:
$ sudo nano postgressetup.sql
CREATE SCHEMA schma;
CREATE USER a2i WITH PASSWORD 'password';
GRANT CONNECT ON DATABASE postgres TO schma;
This file has all the queries. I tried something like:
$ psql -U postgres -d postgres -a -f postgressetup.sql
and received error:
psql: FATAL: Peer authentication failed for user "postgres"
I want to know the way I can execute this .sql file.
Note: I've just installed postgres and no further operation is done on it. Any help is appreciated.
You can use the following command explicitly providing db context user
sudo -u postgres psql -U postgres -d postgres -a -f postgressetup.sql

Restore Postgres database using pg_restore over SSH

I have a database server without much disk space, so I took a backup of the entire db (let's just call it redblue) and saved it locally using the following command (I don't have pg running on my computer):
ssh admin#w.x.y.z "pg_dump -U postgres redblue -h localhost " \
>> db_backup_redblue.sql
I'd like to now restore it to another server (1.2.3.4) which contains an older version of "redblue" database - however wanted to ask if this is right before I try it:
ssh admin#1.2.3.4 "pg_restore -U postgres -C redblue" \
<< db_backup_redblue.sql
I wasn't sure if I need to do -C with the name of the db or not?
Will the above command overwrite/restore the remote database with the file I have locally?
Thanks!
No, that will do nothing good.
You have to start pg_restore on the machine where the dump is. Actually, since this is a plain format dump, you have to use psql rather than pg_restore:
psql -h 1.2.3.4 -U postgres -d redblue -f db_backup_redblue.sql
That requires that there is already an empty database redblue on the target system.
If you want to replace an existing database, you have to use the --clean and --create options with pg_dump.
If you want to use SSL, you'll have to configure the PostgreSQL server to accept SSL connections, see the documentation.
I'd recommend the “custom” format of pg_dump.
Of course, you can do this :) Assuming you use ssh keys to authorize user from source host to destination host.
On the source host you do the pg_dump, then pipe through ssh to destination host like this:
pg_dump -C nextcloud | ssh -i .ssh/pg_nextcloud_key postgres#192.168.0.54 psql -d template1
Hope that helps ;)

How do I connect to psql when it cannot connect to the server?

When I typed psql in the terminal I get the below:
psql: could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/var/pgsql_socket/.s.PGSQL.5432"?
My brew services list shows that Postgres is running:
postgresql#9.5 started john doe /Users/johndoe/Library/LaunchAgents/homebrew.mxcl.postgresql#9.5.plist
Run this to determine, where is your cluster data directory (the directory, where Postgres keeps data, WAL logs, etc):
sudo ps ax | grep postgres | grep D
If Postgres is running, you will see smth like this (this is Postgres.app, not Homebrew version, but it should be similar):
Nikolays-MacBook-Pro:~ nikolay$ sudo ps ax | grep postgres | grep D
Password:
599 ?? S 0:00.06 /Users/nikolay/PostgreSQL/pg96/bin/postgres -D /Users/nikolay/PostgreSQL/data/pg96 -r /Users/nikolay/PostgreSQL/data/logs/pg96/postgres.log
Go to the cluster directory ("/Users/nikolay/PostgreSQL/data/pg96" in this example) and open postgresql.conf, it should be there.
You need to find, what is set in the following options in your postgresql.conf:
listen_addresses
port
These two configurations tell you, on which network interfaces and which port Postgres is sitting.
In most cases, they are like this:
listen_addresses = '*'
port = 5432
There is additional config files, pg_hba.conf, you can consider it like an "internal firewall" for Postgres -- check rules, that are inside, and if needed, edit them. Remember, that if you edit any of connection settings, Postgres needs to be restarted.
In this case, to connect to Postgres, you need:
psql -h localhost -p 5432 -U postgres template1
Here I assumed that you installed Postgres under "postgres" OS user and during installation the corresponding database user was created. Probably you need to try different way:
psql -h localhost -p 5432 -U yourname template1
-- template1 is a default database which is a template for all DBs you will create, so you can try to connect to it anytime. "yourname" is your MacOS username.
Of course, "-p 5432" can be omitted because 5432 is Postgres' default port.
"-U yourname" can be also omitted -- in this case psql will take your OS username and use it like a DB username. And you can omit DB name also if it is the same as database username. So in some cases, "psql -h localhost" will work.
Hope it helps.

Modifying postgresql.conf through shell?

I want to modify a postgresql.conf parameter through the shell. From the documentation I can see that I can use the postgres command with the -c flag.
However, on my attempt, for example,
postgres -c autovacuum=off
postgres returns:
Execution of PostgreSQL by a user with administrative permissions is not permitted.
The server must be started under an unprivileged user ID to prevent possible system security compromises. See the documentation for more information on how to properly start the server.
How can I overcome this or what is the correct procedure? Also, I don't really mind for security compromises.
Given the differences on the underlying OS, I usually prefer to do this via PostgreSQL itself, which comes handy when you're dealing with a managed service that do not give you filesystem access, like so:
sudo -u postgres psql -U postgres -d database_name -c "alter system set postgresql_parameter = 'new_value';"
As an example when I have to install TimeScaleDB extension, I can do:
sudo -u postgres psql -U postgres -d database_name -c "alter system set shared_preload_libraries = 'timescaledb';"
sudo service postgresql restart
sudo -u postgres psql -U postgres -d database_name -c "create extension if not exists timescaledb;"