I've previously been using PostgreSQL in Ubuntu using:
$sudo -i -u postgres
to access postgres through the terminal to create a role and database. And then able to log in and make changes using:
$sudo -u [dbname] psql
However now I need to use PostgreSQL with LabVIEW so I've had to download PostgreSQL on a Windows PC. I can access the database through Pgadmin and have created a database but when I go into SQL shell it comes up with:
Server [localhost]:
Database [postgres]:
Port [5432]:
Username [postgres]:
I'm not sure if this has anything to do with roles, as I haven't created one for the windows database. But I can't even get past the above to create a role or make any changes in the command prompt.
When I type my computer host name, it says
psql: could not translate host name "Lisa" to address: Unknown host
It says I am connected on PgAdmin and I am able to create databases and tables through the interface, but I can't figure out how to access it in the SQL Shell (psql).
Entered server as localhost IP.
Server [localhost]: 127.0.0.1
Database [localhost]: [dbname]
Port [5432]: 5432
Username [postgres]: [username]
Related
This is my first time working with Laravel, and I have a project set up, but I cannot connect to the database I created in Postgres. Whenever I try to connect to the database for a query (or anything), I get this error:
PDOException
SQLSTATE[08006] [7] FATAL: password authentication failed for user "marlie" FATAL: password authentication failed for user "marlie"
I'm using Windows 10, PostgreSQL 11, Laravel 6.0.4. I can connect to the database through pgAdmin4, command line, and psycopg2 without any password authentication issues. Only Laravel is giving me a hard time.
I've tried creating a new Laravel project, creating a new superuser (which I've tested, can successfully access the database from the other programs I mentioned above). I've also tried putting the username and password in both single and double quotes. I tried changing the database name to the OID number value in my postgreSQL file for the database. I've also tried adding the absolute file directory. I've tried changing port from 5432 to 54320. I've also tried other passwords.
Some search results suggested I play with the pg_hba.conf file and adding some lines such as (the indentation here is a little funny, but in the actual file it's all lined up):
local all marlie md5
local all marlie trust
host all all ::1/0 trust
host all all all trust
I've also tried changing everything to trust, in which case I can log in from command line without a password, but Laravel still won't let me! Also, my Windows laptop doesn't seem to support local connections since they're Unix-socket domains, so any local entries in pg_hba.conf end with the file not being able to load at all. Currently, my pg_hba.conf file is back to the default settings.
I've tried logging in by ssh into my Laravel project through Homestead.
$ vagrant ssh
$ psql -d natureFun -U marlie -W
Password:
psql: FATAL: Peer authentication failed for user "marlie"
I thought this was interesting because nowhere in my conf file do I say to use peer authentication. I've only ever tried trust and md5.
This is my .env file from Laravel
DB_CONNECTION=pgsql
DB_HOST=127.0.0.1
DB_PORT=5432
DB_DATABASE=natureFun
DB_USERNAME=marlie
DB_PASSWORD=secret
This is pg_hba.conf
# TYPE DATABASE USER ADDRESS METHOD
# IPv4 local connections:
host all all 127.0.0.1/32 md5
# IPv6 local connections:
host all all 127.0.0.1/32 md5
# Allow replication connections from localhost, by a user with the
# replication privilege.
host replication all 127.0.0.1/32 md5
host replication all ::1/128 md5
It seems that your first pg_hba.conf has a typo:
host all all all trust
Should be:
host all all <ip_address>/<netmask> trust
If it's a dev machine and you don't care about security (for now), just try:
host all all 0.0.0.0/0 trust
Also, unless you're acutally using IPv6, I'd recommend getting rid of the entire line containing ::1/0
Your second pg_hba.conf that you pasted should work, given that you restarted/reloaded the postmaster process -- you can usually do that through pg_ctl reload from the terminal or SELECT pg_reload_conf() from psql
Disclosure: I am an EnterpriseDB (EDB) employee
SOLVED! I misunderstood how Homestead worked (and also failed to mention that I am using it, sorry!)
when I put localhost or 127.0.0.1 in my .env file in my Laravel project, it references the Homestead Virtual as the localhost, NOT my actual computer.
Changing DB_HOST to my computer's IP address solved the problem and I am now happily connected.
Sorry for the noob question but I am new to Oracle SQL software.
I've been trying to create a connection to my database student (created on SQL Developer), but got quite confusing since I'm using a client-computer which will connect to server.
Below are the info about the connection:
Connection Name: LARGER123
Username: LARGER123
Hostname: uxkg265.admin.plent
Port: 1520
SID: ticp5076
Client-computer username: r5678
When I open the SQL Plus prompt, I tried several combinations on the username in order to establish the connection, but got the same error ORA-12154 Error.
I though that it could be the way I was setting the things on username field, so I followed the instructions from Oracle's website:
https://docs.oracle.com/database/121/ADMQS/GUID-1A15D322-B3AC-426A-86A1-EB7590930687.htm#ADMQS045
Basically it tells to "build" the username structure in that way:
nick#"dbhost.example.com/orcl.example.com"
Where: "nick" is the user; "dbhost.example.com" is the host; and "orcl.example.com" is the database.
So, following the example I put my username in that way and got errors:
LARGER123#"uxkg265.admin.plent/student"
I tried different ways, including the Port and SID but got no success.
Do you have a better idea of what's my mistake?
Are you quite certain somebody is listening where you are trying to connect. I would suggest you start by testing with telnet.
You say your server has the domain name “uxkg265.admin.plent”
nslookup uxkg265.admin.plent
I just checked my IP address and found:
$ nslookup $(hostname)
Server: xxx.xxx.xxx.xxx
Address: xxx.xxx.xxx.xx##53
Name: mydomain.myorg.com
Address: 192.168.56.1
I just tried to connect to my oracle instance and got:
$ telnet 192.168.56.1 1521
Trying 192.168.56.1...
Connected to 192.168.56.1
Escape character is '^]'.
^]
telnet> quit
Connection closed.
If I try to the wrong port, I get:
$ telnet 192.168.56.1 1522
Trying 192.168.56.1...
telnet: connect to address 192.168.56.1: Connection refused
I was able to connect with:
sqlplus myoracle/testpass#192.168.56.1:1521/UPGR
where UPGR is the service name.
I was also able to connect with:
sqlplus myoracle/testpass#"(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.56.1)(PORT=1521))(CONNECT_DATA=(SID=UPGR)))"
With UPGR as the SID.
I had some trouble initially because my version of Oracle Linux had iptables enabled and that was keeping me from connecting using sqlplus. As soon as I disabled this protection, I was able to use Oracle.
sudo service iptables stop
sudo chkconfig iptables off
(Keep in mind that iptables serves a purpose. For my test system running on my PC in VirtualBox, turning it off is fine. For other systems, maybe not.)
ORA-12154 is TNS:could not resolve the connect identifier specified, but you likely aren't using TNS to resolve the connect identifier: have you edited the tnsnames.ora file on the client machine and created an entry for the SID you're trying to connect to? Probably not.
Instead of selecting SID, select "Service name" and put the Oracle SID there. With the "Basic" connection type, that should use the host/port and service name explicitly to build the connection rather than relying on TNS to look up (resolve) the SID.
I have a Windows PostgreSQL installation.
According to some posts, there is no default password set for the 'postgres' user yet I can't connect using an empty password string.
I'm receiving this exception when I try to connect:
Caused by: org.postgresql.util.PSQLException: FATAL: password authentication failed for user "postgres"
The most relevant tip was this:
https://stackoverflow.com/a/25943227/1005607
Open pg_hba.conf
Change md5 -> TRUST
then restart PgAdmin.
I tried that and restarted PGAdmin but it still asks me for the password when I try to connect:
The task manager in Windows shows some PostgreSQL processes are running. I can't switch them off.
I have tried this and it failed:
pg_ctl restart
ERROR:
pg_ctl: no database directory specified and environment variable PGDATA unset
psql.exe postgres
Password: (none)
ERROR:
psql: fe_sendauth: no password supplied
How can I reset the default password for user 'postgres'?
Based on AK47's answer and some additional info I fixed it by doing the following,
1) Stop Postgres if currently running, command line below. Need to give it the 'data' dir. In my case C:\PostgreSQL\data
pg_ctl -D C:\PostgreSQL\data stop
2) Edit the file pg_hba.conf (it's also in the \data dir) as follows:
As AK40 wrote, change all MD5 references to trust , e.g.
# TYPE DATABASE USER ADDRESS METHOD
# IPv4 local connections:
host all all 127.0.0.1/32 trust
# IPv6 local connections:
host all all ::1/128 trust
# Allow replication connections from localhost, by a user with the
# replication privilege.
host replication all 127.0.0.1/32 trust
host replication all ::1/128 trust
3) Now run
psql -U postgres
4) In the PG Command Prompt that appears type,
ALTER USER Postgres WITH PASSWORD '<newpassword>';
5) Save this by typing wq enter to exit the PG Prompt
6) Now start Postgres
pg_ctl -D C:\PostgreSQL\data start
7) Might want to revert the MD5 -> Trust change later in the pg_hba.conf.
Update your pg_hba.conf file to allow for trusted local connections
[root#server] vim pg_hba.conf
>> local all all trust
then restart your PostgreSQL server
[user#machine] pg_ctl -D C:\PostgreSQL\data restart (Windows)
[root#server] service postgresql restart (Linux)
at this point you can connect to your server as postgres user using a local connection without the need to enter a password (omitting the -h parameter when calling the psql command will use a local connection - if you pass -h then this will match the line host all all 0.0.0.0/0 <method> in your pg_hba.conf file)
[root#server] psql -U postgres
You can then alter the postgres user role and set the password to whatever you like using the following command in the psql terminal
[psql] alter role postgres password <new_password>;
Once this is done you can restart your PostgreSQL server again
[user#machine] pg_ctl -D C:\PostgreSQL\data restart (Windows)
[root#server] service postgresql restart (Linux)
and at this point your password should be changed to the new password
I was having the same issue and I couldn't use Postgres in the CLI on my windows machine but I managed to trace down where the passwords were stored via
%APPDATA%\PostgreSQL\pgpass.conf
NB: You must have selected store password option when creating a server or database in the pgAdmin.
I hope this helps. Thanks.
I'm trying to create a backup in postgresql 9.3 on windows 7 in two PC
In PC_A I can do without problems
c:\Program Files\PostgreSQL\9.3\bin>pg_dump -U postgres -C -f C:\uti\sample.bak template1
But in the PC_B say Access is denied
I try modify the pg_hba.conf file and put trust my ip address and restart postgres service.
host all all 127.0.0.1/32 trust
host all all 192.168.0.0/16 trust
I can enter psql ok in PC_B with
psql -U postgres template1
Also I'm running cmd as Administrator
I can create file ok
What else I'm missing?
You only need add C:\Program Files\PostgreSQL\13\bin (postgres path) to PATH in eviroment variables , close the terminal or vscode and check it again , it works for me.
I use Vagrant and Codception, but when i want to test application localy, I must do it on LAMP (or something like that) server. How can I use database on Vagrant?
All you need is just to setup access to your mysql server that runs on the guest machine (vagrant box) from the host and then to set appropriate database DNS in your codeception.yml config.
Here is some general instructions:
1) Allow your vagrant's mysql server listen all interfaces ssh to your box by setting 'bind-address' option in mysql's my.cnf config and change it's value to 0.0.0.0
2) Grant appropriate privileges to mysql user that will be used to connect to database from the host.
You can do this running following SQL commands using mysql client
USE mysql;
GRANT ALL ON *.* to root#'192.168.0.1' IDENTIFIED BY 'mypass';
FLUSH PRIVILEGES;
where root and mypass - your database user which will be used from codeception to connect to database and its password and 192.168.0.1 - the ip of the host (read how get host's ip for your gest here)
3) Restart vagrant's mysql server
4) To test connection to vagrant's mysql from the host run
mysql -h 192.168.33.10 -P 3306 -u root -p
(Here 192.168.33.10 - ip of my running vagrant box)
5) Set up DNS in codeception.yml file, e.g.
modules:
config:
Db:
dsn: 'mysql:host=192.168.33.10;dbname=MyDB'
user: 'root'
password: 'mypass'