1、安装rpm文件
yum install https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm
2、安装客户端
yum install postgresql10
3、安装服务端
yum install postgresql10-server
4、初始化
/usr/pgsql-10/bin/postgresql-10-setup initdb
5、设置自动启动并且启动postgresql服务
systemctl enable postgresql-10
systemctl start postgresql-10
登录
su - postgres
psql
退出
\q
create user test_user with password 'abc123'; // 创建用户
create database test_db owner test_user; // 创建数据库
grant all privileges on database test_db to test_user; // 授权
drop table student2; 删除表
CREATE TABLE student(id integer,name varchar,sex varchar); 创建表
INSERT INTO student(id,name,sex)VALUES(1,'Aspirin','M'); 插入数据
CREATE TABLE student2(id smallint,name varchar,sex varchar);
INSERT INTO student2(id,name,sex)VALUES(1909,'Aspirin','M');
CREATE TABLE student3(id smallint,id2 integer,id3 bigint,name varchar,sex varchar);
INSERT INTO student3(id,id2,id3,name,sex)VALUES(19090,2121290,212019200,'Aspirin','M');
CREATE TABLE student4(id real,id2 double precision,id3 smallserial,id4 serial,id5 bigserial,name varchar,sex varchar);
INSERT INTO student4(id,id2,id3,id4,id5,name,sex)VALUES(28982932,09898984938439,9092,21209093,809840389042,'Aspirin','M');
CREATE TABLE student6(id decimal,id2 numeric,name varchar,sex varchar);
INSERT INTO student6(id,id2,name,sex)VALUES(12331314414141,211212114441213,'Aspirin','M');
CREATE TABLE student7(id decimal(30,2),id2 numeric(90,3),name varchar,sex varchar);
INSERT INTO student7(id,id2,name,sex)VALUES(123313.14,2112121144412.13,'Aspirin','M');
CREATE TABLE student8(id numeric(90,3),name varchar,sex varchar);
INSERT INTO student8(id,name,sex)VALUES(123313.14,'Aspirin','M');
CREATE TABLE student9(id numeric(5,2),name varchar,sex varchar);
INSERT INTO student9(id,name,sex)VALUES(100.01,'Aspirin','M');
CREATE TABLE student10(id decimal(5,2),id2 numeric(5,2),name varchar,sex varchar);
INSERT INTO student10(id,id2,name,sex)VALUES(100.14,100.13,'Aspirin','M');
切换数据库
\c postgres;
修改远程访问
-bash-4.2$ vi /var/lib/pgsql/10/data/postgresql.conf
listen_addresses = '*'
-bash-4.2$ vi /var/lib/pgsql/10/data/pg_hba.conf
# IPv4 local connections:
#host all all 127.0.0.1/32 ident
在idnet下增加一行
host all all 0.0.0.0/0 md5
-bash-4.2$ exit
登出
重启
systemctl restart postgresql-10.service
1、修改默认生成的 postgres 用户密码(此postgres非上面的postgres用户,此为数据库的用户,上面的为操作系统的用户)
su - postgres
psql -U postgres
alter user postgres with encrypted password '123456';
二 python连接postgresql
yum -y install epel-release
yum -y install python-pip
yum -y install python-psycopg2
kafka查看topic
bin/kafka-topics.sh --list --zookeeper localhost:2181
kafka查看topic中数据
/opt/kafka/bin/kafka-console-consumer.sh --bootstrap-server 10.0.2.20:9092 --topic JDBC02 --from-beginning