Error-shooting when installing & Configuring PostgreSQL under Windows WSL Linux

PRE REQ:

1. Windows 11 Home Edition & WSL2 Linux Ubuntu 22.04.2 LTS

2. PostgreSQL & PGAdmin already installed in Windows OS, and PostgreSQL installed in     Linux OS (further config is not required, only basic installation commands are needed)

ERRORS: 

1. 

command input: 

psql -U postgres

error generated:

psql: error: connection to server on socket "/var/run/postgresql/.s.PGSQL.5432" failed: FATAL:  Peer authentication failed for user "postgres"

possible causes:

(1). System username and PostgreSQL database username are seperated and stored in seperate doamains, where WSL is defaulted to load current username while database username is set default to be "postgres"

(2). PostgreSQL authentication is wrongly set and current user has no access to wanted database

feasible solutions (one-to-one):

(1). 

sudo -u postgres psql

sudo command with -u flag forces psql to run with username "postgres"

(2).

cd to pg_hba.conf, which normally locates in:

/etc/postgresql/14/main/pg_ident.conf

change this line:

local   all             all                                     peer

into:

local   all             all                                     md5

or:

local   all             all                                     all

where md5/all grants access to all users. 

2.

In sql copy command "copy TABLE_NAME(col1, col2, ...) from FILE_PATH with XXX", absolute path is required for FILE_PATH. Note that "C:/" or "D:/" is NOT root path in wsl or wsl2. Notice that on logging in to wsl, you are redirected to:

/mnt/c/Users/<username>

where parent dir of mnt is deemed as root dir. Suppose you get a dir in local disk (D:) named test and you gotta copy sth from there, you will key in 

/mnt/d/temp

to get redirected. Remember to have "/" in the front, which denotes the start of file path.

(to be continued and subject to modifications)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值