What is the correct way to run .sql script using psql?
When I do like this
psql D:\scripts\script.sql
It requires password. I pass my db password pass but it shows error
password authentication failed for user PC_ADMIN
(i.e. my windows user). But my db user has the name postgres.
How to set in command psql D:\scripts\script.sql\ user and password?
Try like this:
psql -U username -d myDataBase -a -f script.sql
you have to send the user flag to the script,
psql D:\scripts\script.sql -U whateveruser
OR
psql D:\scripts\script.sql --username=whateveruser
otherwise it will assume that the user is the current OS account.
Related
I a rails app running on my local environment using postgresql. This morning I spun up a new one and after install the pg gem, etc. I am running into the following error when trying to run
psql
psql: error: connection to server on socket "/tmp/.s.PGSQL.5432" failed: FATAL: database "jackcollins" does not exist
What's strange is the db name "jackcollins" is from my other rails app.
I ran
pgrep -l postgres
and the output was
20902 postgres
20919 postgres
20920 postgres
20921 postgres
20922 postgres
20923 postgres
20924 postgres
I'm unsure how to proceed so that these apps can both run their own postgres instance.
I had the same problem as you, after making attempts to reinstall, rm -rf xxx.pid, etc., I ended up executing the following command and was eventually able to connect to the PostgreSQL database.
brew install postgresql
an error message appears
run createdb (because macs don't create username databases after installing PostgreSQL)
execute psql to connect successfully.
Regarding the error, you are trying to connect to jackcollins, please can you test trying to connect using the database flag?:
psql -d your_database_name
If you type
psql --help
in the terminal, you will see that the default database is your username. Unless you have that database in PostgreSQL, you will get an error. Instead, you can run the command
psql -d your_database_name
Also, if you want to log in as a specific user (by default it is a current user):
psql -d your_database_name -U your_username -W
The last -W is for password. Hope, it helps!
In the absence of -d <database_name> psql will use the OS user name as the database name. As in many things it better to be explicit rather then implicit, especially when working on a new instance. In addition use -h <host_name>, -p <port_number> and -U <user_name>. Then you know who you are connecting as, as well as how. It is spelled out here psql and since psql is a libpq program in more detail here Key words.
I have script that user can change password to ldap. The user write his password and the script is sending the command to ldap server. I can`t do that other way, only this way ldap server creates propper passwords. The command is:
ldappasswd -x -D "uid=userwhocanchangepassword,cn=users,dc=example,dc=org" -w "userpass" -h ldap.host -S 'uid=usertochange,cn=users,dc=example,dc=org' -s 'passwordTochange'
userwhocanchangepassword - is user that has perrmissions to change other users passwords
Autside the container it works perfectly (password is changed) but when I try to run same command in the docker container insted of password change i get ldappasswd help:
Change password of an LDAP user
usage: ldappasswd [options] [user]
user: the authentication identity, commonly a DN
It`s strange but it works well if I delete the -s param with the password. But if I do that command is prompting to pass the password.
On my dev machine and inside the docker container is the same version of the ldappasswd. Docker is ubuntu container with installed ldap-utils.
Is any other way to modify this command, or maybe some one has simillar problem?
Thanks for any help.
I've created a Bitnami Dokuwiki Docker container on my Mac using:
curl -sSL https://raw.githubusercontent.com/bitnami/bitnami-docker-dokuwiki/master/docker-compose.yml > docker-compose.yml
docker-compose up -d
I can connect to it in my browser, and there is a login link, but no way I can find to create a user.
Is there a default user, hopefully an admin user? Or do I need to create a user another way?
The default login is superuser, bitnami1.
It sets up this superuser account when you initially create the container. You can change the username and password it uses by passing environment variables DOKUWIKI_USERNAME and DOKUWIKI_PASSWORD to docker with -e.
I ran the following command to backup my PostgreSQL database:
pg_dump -U postgres -h localhost -W -F t crewdb > /home/chris1/Documents/crewcut/crewdb/crewdb_bak.tar
This file was later saved to a USB.
After installing PostgreSQL on a new Ubuntu 18.04 system I ran the following command to restore the database from the USB:
psql -U postgres -d crewdb < /media/chh1/1818-305D/crewdb_bak.tar
The structure of the database has been recovered, so tables, views etc. except the actual data in the tables which has not been recovered.
Has anyone got an idea why this is and how to solve this.
I do not know if the command you ran to restore your data is correct; on any case try to use the pq_restore as says from the official documentation "restore a PostgreSQL database from an archive file created by pg_dump" that's the correct way to do it.
In my case I use pg_dumpall -U user > backup.sql then "cat backup.sql | psql -U user database"
I recommend you to check out the flags you're using on your pg_dump
What does the below command mean that you "login as root"? I don't understand when do you create a user or when you don't have to. If you're logging in as root, does that mean you're just the official super user or something that can create all other users? What's the difference between this and creating other users/roles? If I can get an analogy to understand that would be great.
su - postgres
It switches your unix user and unix shell to the unix postgres user. That's all.
(Don't do that, use sudo -u postgres instead).
At a guess, you're doing that because you then want to run psql. By default on most installs psql will connect to postgres with the same postgres username as your unix user name. So switching to unix user postgres then runnining psql will get you a postgres session as the postgres user, which usually has superuser rights to the database.