PostgreSQL服务启动时报错:“FATAL: could not create lock file "/tmp/.s.PGSQL.5432.lock": Permission denied”
PostgreSQL服务启动时报错:FATAL: could not create lock file "/tmp/.s.PGSQL.5432.lock": 权限不够
PostgreSQL服务启动时报错:FATAL: could not open lock file "/tmp/.s.PGSQL.5432.lock": 权限不够
FATAL: could not create lock file "/tmp/.s.PGSQL.5432.lock": Permission denied
1:添加linux用户及创建数据库目录
addgroup postgresql
adduser -G postgresql postgresql 此处需要输入密码,后面有此密码来链接数据库
mkdir -p /usr/local/pgsql/data
mkdir -p /usr/local/pgsql/log
touch /usr/local/pgsql/log/pgsql.log
2:更改数据库目录所属权限
chown -R postgresql:postgresql /usr/local/pgsql/data
chown -R postgresql:postgresql /usr/local/pgsql/log
chown -R postgresql:postgresql /usr/local/pgsql/log/pgsql.log
chown -R postgresql:postgresql tmp
3:创建数据库用户(可忽略)
createuser -sADEP postgresql
此处需要输入密码,用来连接数据库
4:初始化及启动数据库
./initdb -D /usr/local/pgsql/data
./pg_ctl -D /usr/local/pgsql/data -l /usr/local/pgsql/log/pgsql.log start
[postgresql@iTOP-4412 /binpost/bin]$./pg_ctl -D /usr/local/pgsql/data -l /usr/local/pgsql/log/pgsql.log start
server starting
5:登陆到postgresql命令行/创建数据库及表,添加纪录。
首先需要以之前创建的用户登录 postgresql
psql postgres
执行命令的时候,出现如下问题:
[postgresql@iTOP-4412 /binpost/bin]$./psql postgres
psql: could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/tmp/.s.PGSQL.5432"?
百度之后是权限的问题:
对/tmp目录的所属权限进行设置
[postgresql@iTOP-4412 /binpost/bin]$ su - root
[root@iTOP-4412]# ls
bin etd proc usr
binpost home root var
binpost.tar.bz2 lib sbin work
createsocket linuxrc showtable
dev mnt sys
etc opt tmp
[root@iTOP-4412]# chown -R postgresql:postgresql tmp
[root@iTOP-4412]# su postgresql
[postgresql@iTOP-4412 /binpost/bin]$./pg_ctl -D /usr/local/pgsql/data -l /usr/lo
cal/pgsql/log/pgsql.log start
server starting
[postgresql@iTOP-4412 /binpost/bin]$./psql postgres
psql (9.1.9)
Type "help" for help.
postgres=# CREATE DATABASE psmp;
postgres=# \l
List of databases
Name | Owner | Encoding | Collate | Ctype | Access privileges
-----------+------------+-----------+---------+-------+---------------------------
postgres | postgresql | SQL_ASCII | C | C |
psmp | postgresql | SQL_ASCII | C | C |
template0 | postgresql | SQL_ASCII | C | C | =c/postgresql +
| | | | | postgresql=CTc/postgresql
template1 | postgresql | SQL_ASCII | C | C | =c/postgresql +
| | | | | postgresql=CTc/postgresql
(4 rows)
创建表company并添加纪录
CREATE TABLE COMPANY(
ID INT PRIMARY KEY NOT NULL,
NAME TEXT NOT NULL,
AGE INT NOT NULL,
ADDRESS CHAR(50),
SALARY REAL,
JOIN_DATE DATE
);
INSERT INTO COMPANY (ID,NAME,AGE,ADDRESS,SALARY,JOIN_DATE) VALUES (1, 'Paul', 32, 'California', 20000.00 ,'2001-07-13');
INSERT INTO COMPANY (ID,NAME,AGE,ADDRESS,SALARY,JOIN_DATE) VALUES (3, 'Teddy', 23, 'Norway', 20000.00, DEFAULT );
6:直接登录数据库
[postgresql@iTOP-4412 /binpost/bin]$
[postgresql@iTOP-4412 /binpost/bin]$
[postgresql@iTOP-4412 /binpost/bin]$./psql -d psmp -U postgresql
psql (9.1.9)
Type "help" for help.
psmp=# \d
List of relations
Schema | Name | Type | Owner
--------+---------+-------+------------
public | company | table | postgresql
(1 row)
psmp=# select * from company;
id | name | age | address | salary | join_date
----+-------+-----+----------------------------------------------------+--------+------------
1 | Paul | 32 | California | 20000 | 2001-07-13
3 | Teddy | 23 | Norway | 20000 |
(2 rows)
psmp=#
更多推荐
所有评论(0)