~/.psqlrc file is ignored

Started by vstuartalmost 9 years ago10 messagesgeneral
Jump to latest
#1vstuart
mail@VictoriasJourney.com

My ~/.psqlrc file is ignored by my PostgreSQL installation (v.9.6.3; Arch
Linux x86_64 platform).

Suggestions?

--
View this message in context: http://www.postgresql-archive.org/psqlrc-file-is-ignored-tp5971773.html
Sent from the PostgreSQL - general mailing list archive at Nabble.com.

--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general

#2Thom Brown
thom@linux.com
In reply to: vstuart (#1)
Re: ~/.psqlrc file is ignored

On 18 July 2017 at 19:02, vstuart <mail@victoriasjourney.com> wrote:

My ~/.psqlrc file is ignored by my PostgreSQL installation (v.9.6.3; Arch
Linux x86_64 platform).

Suggestions?

Do you get anything with "psql -a"?

If not, what do you get when you use "psql -af ~/.psqlrc" ?

Thom

--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general

#3vstuart
mail@VictoriasJourney.com
In reply to: Thom Brown (#2)
Re: ~/.psqlrc file is ignored

Hi Thom: thank you for your reply; I can't figure this one out! Per your reply:

[victoria@victoria ~]$ pg
[sudo -u postgres -i]
[sudo] password for victoria:

[postgres@victoria ~]$ psql -a
psql (9.6.3)
Type "help" for help.

postgres=# \q

[postgres@victoria ~]$ psql -af ~/.psqlrc
/var/lib/postgres/.psqlrc: No such file or directory

[postgres@victoria ~]$ exit
logout

[victoria@victoria ~]$

So, it appears that postgres is looking for the .psqlrc file there (does not exist), but ignoring my ~/.psqlrc file, right?

Edit: from that, it appears that postgres thinks that my home directory is /var/lib/postgres/. ... Confirmed:

[postgres@victoria ~]$ echo $HOME
/var/lib/postgres

As a simple solution, I can sudo symlink MY ~/.psqlrc to that directory (/var/...; changing ownership also to postgres), but there appears to be some underlying issue, as Pg should find ~/.psqlrc, correct?

FYI, I installed postgresql (Arch Linux) using the "pacman" package manager; the only significant change I made is to define a custom data directory, on my home partition.

----------------------------------------
From: "Thom Brown-2 [via PostgreSQL]" <ml+s1045698n5971968h76@n3.nabble.com>
Subject: Re: ~/.psqlrc file is ignored
Date: Wed, 19 Jul 2017 11:31:49 -0700 (MST)

Do you get anything with "psql -a"?

If not, what do you get when you use "psql -af ~/.psqlrc" ?

Thom

--
View this message in context: http://www.postgresql-archive.org/psqlrc-file-is-ignored-tp5971773p5971973.html
Sent from the PostgreSQL - general mailing list archive at Nabble.com.

#4David G. Johnston
david.g.johnston@gmail.com
In reply to: vstuart (#3)
Re: ~/.psqlrc file is ignored

On Wed, Jul 19, 2017 at 11:49 AM, vstuart <mail@victoriasjourney.com> wrote:

As a simple solution, I can sudo symlink MY ~/.psqlrc to that directory
(/var/...; changing ownership also to postgres), but there appears to be
some underlying issue, as Pg should find ~/.psqlrc, correct?

​What does "your" ~/.psqlrc have to do with any of this? If you are
executing psql while masquarding at the postgres user its the postgres
user's​ ~/.psqlrc file that will be looked for.

Typically one doesn't execute psql as the postgres user. They configure
the system so that they can execute psql as a regular user. You should
probably do that and then everything should work like you are thinking.

David J.

#5vstuart
mail@VictoriasJourney.com
In reply to: David G. Johnston (#4)
Re: ~/.psqlrc file is ignored

Hi David: I see what you are saying; sorry for the confusion. This is how postgres operates on my system:

[victoria@victoria ~]$ echo $HOME
/home/victoria

[victoria@victoria ~]$ which postgres
/usr/bin/postgres

[victoria@victoria ~]$ postgres
postgres does not know where to find the server configuration file.
You must specify the --config-file or -D invocation option or set the PGDATA environment variable.

[victoria@victoria ~]$ psql
psql: FATAL: database "victoria" does not exist

[victoria@victoria ~]$ sudo -u postgres -i

[postgres@victoria ~]$ echo $HOME
/var/lib/postgres

[postgres@victoria ~]$ psql
psql (9.6.3)
Type "help" for help.

postgres=# \q

[postgres@victoria ~]$ exit
logout

[victoria@victoria ~]$

... That postgres had a different $HOME environment than mine was not apparent to me, when I posted this question.

What does "your" ~/.psqlrc have to do with any of this? If you are
executing psql while masquarding at the postgres user its the postgres
user's​ ~/.psqlrc file that will be looked for.

Typically one doesn't execute psql as the postgres user. They configure
the system so that they can execute psql as a regular user. You should
probably do that and then everything should work like you are thinking.

--
View this message in context: http://www.postgresql-archive.org/psqlrc-file-is-ignored-tp5971773p5971984.html
Sent from the PostgreSQL - general mailing list archive at Nabble.com.

#6David G. Johnston
david.g.johnston@gmail.com
In reply to: vstuart (#5)
Re: ~/.psqlrc file is ignored

On Wed, Jul 19, 2017 at 12:12 PM, vstuart <mail@victoriasjourney.com> wrote:

Hi David: I see what you are saying; sorry for the confusion. This is how
postgres operates on my system:

​None of that is surprising or unique. If you ask specific questions I'd
be willing to answer them but I'm not going to explain everything that is
going on line-by-line.

David J.

#7vstuart
mail@VictoriasJourney.com
In reply to: vstuart (#5)
Re: ~/.psqlrc file is ignored [solved: $HOME/.psqlrc]

'Solution,' for anyone else encountering this issue (Arch Linux PostgreSQL
install ...).

TLDR: symlink ~/.psqlrc to postgres $HOME/.psqlrc

-----------------------------------------------------

[victoria@victoria ~]$ echo $HOME
/home/victoria

[victoria@victoria ~]$ ls -la .psq*
-rw-r--r-- 1 victoria victoria 3.9K Jul 17 10:42 .psqlrc

[victoria@victoria ~]$ pg
[sudo -u postgres -i]
[sudo] password for victoria:

[postgres@victoria ~]$ echo $HOME
/var/lib/postgres

[postgres@victoria ~]$ ln -s /home/victoria/.psqlrc /var/lib/postgres/

[postgres@victoria ~]$ ls -la .psqlrc
lrwxrwxrwx 1 postgres postgres 22 Jul 20 08:10 .psqlrc ->
/home/victoria/.psqlrc

[postgres@victoria ~]$ psql

psql:/var/lib/postgres/.psqlrc:14: invalid command \SET
Pager usage is off.
Null display is "[NULL]".
Timing is on.
Expanded display is used automatically.
psql (9.6.3)
Type "help" for help.

[local] postgres@postgres=# \q

## EDITED /home/victoria/.psqlrc in text editor, correcting line 14 error:
## " \SET client_encoding = 'UTF8' " >> " \set CLIENT_ENCODING = 'UTF8' "
## ('\set' needed to be lowercase)

[postgres@victoria ~]$ psql

Pager usage is off.
Null display is "[NULL]".
Timing is on.
Expanded display is used automatically.
psql (9.6.3)
Type "help" for help.

[local] postgres@postgres=# \q

[postgres@victoria ~]$ exit
logout

[victoria@victoria ~]$

--
View this message in context: http://www.postgresql-archive.org/psqlrc-file-is-ignored-tp5971773p5972146.html
Sent from the PostgreSQL - general mailing list archive at Nabble.com.

--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general

#8David G. Johnston
david.g.johnston@gmail.com
In reply to: vstuart (#7)
Re: ~/.psqlrc file is ignored [solved: $HOME/.psqlrc]

On Thu, Jul 20, 2017 at 8:37 AM, vstuart <mail@victoriasjourney.com> wrote:

​​
[victoria@victoria ~]$ pg
[sudo -u postgres -i]
[sudo] password for victoria:

​Just curious, what is going on here?

David J.

#9vstuart
mail@VictoriasJourney.com
In reply to: David G. Johnston (#8)
Re: ~/.psqlrc file is ignored [solved: $HOME/.psqlrc]

~/.bashrc alias:

alias pg='echo " [sudo -u postgres -i]" && sudo -u postgres -i'

--
View this message in context: http://www.postgresql-archive.org/psqlrc-file-is-ignored-tp5971773p5972153.html
Sent from the PostgreSQL - general mailing list archive at Nabble.com.

--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general

#10Thom Brown
thom@linux.com
In reply to: vstuart (#5)
Re: ~/.psqlrc file is ignored

On 19 July 2017 at 20:12, vstuart <mail@victoriasjourney.com> wrote:

Hi David: I see what you are saying; sorry for the confusion. This is how
postgres operates on my system:

[victoria@victoria ~]$ echo $HOME
/home/victoria

[victoria@victoria ~]$ which postgres
/usr/bin/postgres

[victoria@victoria ~]$ postgres
postgres does not know where to find the server configuration file.
You must specify the --config-file or -D invocation option or set the
PGDATA environment variable.

[victoria@victoria ~]$ psql
psql: FATAL: database "victoria" does not exist

By default, psql will attempt to connect to a database named after the
operating system user you are connected as. It will also use that as
the database user name. As you don't have a database of the same name
as your user account, you will need to specify it:

psql -d <databasename> -U <username>

Thom

--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general