进阶数据库系列(三):PostgreSQL 常用管理命令

postgreSQL之grant 欢迎关注留言,我是收集整理小能手,工具翻译,仅供参考,笔芯笔芯. 阅读详情

前面介绍了 PostgreSQL 基础概念及安装部署、目录结构与配置文件 postgresql.conf 相关的知识点,今天我将详细的为大家介绍 PostgreSQL 常用管理命令 相关知识,希望大家能够从中收获多多!如有帮助,请点在看、转发支持一波!!!

登录命令

#连接指定服务器上的数据库
psql -h IP -p 端口 -U 用户名 -d 数据库名 -W

psql 是PostgreSQL的一个命令行交互式客户端工具,它具有非常丰富的功能,类似于Oracle的命令行工具sqlplus。

-h #数据库所在的IP地址
-p #(默认5432)数据库的监听端口
-U #用户名
-d #数据库名称
常用命令说明
\? #所有命令帮助
\l #列出所有数据库
\d #列出数据库中所有表
\dt #列出数据库中所有表
\d [table_name] #显示指定表的结构
\di #列出数据库中所有 index
\dv #列出数据库中所有 view
\h #sql命令帮助
\q #退出连接
\c [database_name] #切换到指定的数据库
\c #显示当前数据库名称和用户
\conninfo #显示客户端的连接信息
\du #显示所有用户
\dn #显示数据库中的schema
\encoding #显示字符集
select version(); #显示版本信息
\i testdb.sql #执行sql文件
\x #扩展展示结果信息,相当于MySQL的\G
\o /tmp/test.txt #将下一条sql执行结果导入文件中

用户管理

创建账号
创建用户
create user 用户名 password '密码';

#设置只读权限
alter user 用户名 set default_transaction_read_only = on;

#设置可操作的数据库
grant all on database 数据库名 to 用户名;

#授权可操作的模式和权限
-- 授权
grant select on all tables in schema public to 用户名;

-- 授权
GRANT ALL ON TABLE public.user TO mydata;
GRANT SELECT, UPDATE, INSERT, DELETE ON TABLE public.user TO mydata_dml;
GRANT SELECT ON TABLE public.user TO mydata_qry;
删除账号
#撤回在public模式下的权限
revoke select on all tables in schema public from 用户名;

#撤回在information_schema模式下的权限
revoke select on all tables in schema information_schema from 用户名;

#撤回在pg_catalog模式下的权限
revoke select on all tables in schema pg_catalog from 用户名;

#撤回对数据库的操作权限
revoke all on database 数据库名 from 用户名;

#删除用户
drop user 用户名;

更多关于大数据 PostgreSQL 系列的学习文章,请参阅:PostgreSQL 数据库,本系列持续更新中。

权限管理

授权
#设置只读权限
alter user 用户名 set default_transaction_read_only = on;

#设置可操作的数据库
grant all on database 数据库名 to 用户名;

#设置可操作的模式和权限
grant select,insert,update,delete on all tables in schema public to 用户名;
撤回权限

        
PostgreSQL 安装、常用命令及优化 ,选择合适的版本。创建一个启动脚本,方便后续启动和管理 PostgreSQL 服务。根据实际业务需求和系统资源情况,还可以进一步调整优化参数。替换为你实际的 CentOS/RHEL 版本(如。首先,访问 PostgreSQL 官方下载页面(编译和安装过程可能需要一些时间,取决于系统性能。在编译之前,需要配置一些编译选项。保存并退出文件,然后重新加载。替换为实际的磁盘设备名。 阅读详情

相关推荐

PostgreSQL 的一些常用命令

的一些常用命令,分为连接数据库、用户和权限管理、表管理、查询数据等多个方面进行讲解,帮助你快速熟悉 PostgreSQL 的操作。

ray_paul1的博客 2258

避坑指南:STM32F4的ADC采样FSR传感器,如何稳定读数并校准压力值?

本文详细解析了STM32F4的ADC采样FSR薄膜压力传感器时遇到的读数不稳定和非线性校准问题,提供了从硬件配置到软件滤波的完整解决方案。通过优化ADC设置、改进滤波算法和实施分段线性校准,帮助工程师实现高精度压力测量,特别适用于智能手套和医疗监测等应用场景。

weixin_28675839的博客 273

【暂时完结】Prescan学习笔记

Prescan学习记录1. Prescan基础知识1.1 Conventions·坐标1.2 Road segment·道路片段1.2.1 让一个路段连接其他两个路段1.2.2 配置车道线1.2.3 Road marking·道路标志1.3 Trajectory·轨迹1.3.1 建立一个Path·路径1.3.2 配置Speedprofile1.3.3 Synchronization of Trajectories·轨迹同步1.3.4 Multiple trajectories · 多轨迹分配 1. Pres

dreautumn的博客 1万+

Synopsys工具链实战:如何用VCS、DC、ICC和Calibre跑通你的第一个数字IC设计项目?

本文详细介绍了如何使用Synopsys工具链(VCS、Design Compiler、ICC和Calibre)完成数字IC设计项目,从RTL代码到GDSII版图的全流程。涵盖环境配置、RTL设计验证、逻辑综合、物理实现及签核验证等关键步骤,帮助工程师掌握高效的数字IC设计流程。

weixin_42525005的博客 197

深信服AC1000-B1200到手第一步:从开箱到激活上网的保姆级图文指南

本文提供深信服AC1000-B1200企业级行为管理设备的详细开局使用指南,涵盖从开箱验机、物理连接到网络配置、安全加固及设备激活的全流程。通过图文并茂的步骤解析,帮助用户快速完成设备初始化并实现安全上网,特别适合初次接触该设备的网络管理员参考。

weixin_42546392的博客 548

iOS应用突然无法从App Store获取到内购(IAP)产品列表的解决

问题现象 Apple开发中,在应用中嵌入内购(IAP)功能的小伙伴们可能会发现,吃着火锅唱着歌,突然App就无法获取到产品列表了,而且产品请求操作并不会返回任何错误。 此时检查发现,并没有对App的内购逻辑做任何改动。 那么,这是什么原因导致的呢? Let’s find out!???? 问题分析 1. 排除其它原因 首先,你先得排除不是你IAP内购逻辑变更或其他原因导致的。 在SKProductsRequestDelegat代理实现的productsRequest方法里下断点: func produc

享受开发,颠倒银河 6142

车载网络测试实操源码_使用CAPL脚本实现安全访问解锁,并模拟各种测试场景

在车载诊断中,我们经常会使用到安全访问解锁,常见的场景包括软件刷写前、通过2E服务写入某个DID前、通过31服务执行某个例程前等,都必须先通过27服务进行安全访问,解锁相应安全等级后才能执行上述操作。在开发调试或测试时,有时候需要模拟正常的安全解锁、安全访问秘钥错误、连续多次请求安全访问等,手动操作极为不便。本文将介绍如何使用CAPL脚本实现安全访问解锁,并模拟各种测试场景。

文章主要涉及嵌入式软件开发、测试、项目管理等,欢迎交流,共同进步。 1201

物联网设备数据是如何流转的:基于EMQX与TDengine的前后端分离项目实践

背景 在我写了TDengine极简实战:从采集到入库,从前端到后端,体验物联网设备数据流转这篇文章后,不少读者朋友评论、私信说可不可以提供代码参考学习下,那必须是可以的。那篇文章主要介绍了数据采集、数据传输、数据转发、数据解析、数据存储、数据查询、数据呈现、数据导出、消息推送的物联网设备数据流程过程,作为体验 TDengine 的极简实战项目,没引入过多的业务设计(复杂功能)以及异步解耦设计(消息中间件)。 在整理代码的过程中,我发现虽然整个项目并不复杂,但是涉及到的技术点较多,有必要对关键的组件进行说明

Heartsuit的博客 9412

【数据集】CMIP6气候模式数据下载

简介CMIP6及其气候模式数据下载

WW、forever的博客 9354

Camera2Demo

在Camera2 的基础上进行封装,使得Camera2一堆初始化逻辑与Activity分离,降低耦合度,完成预览拍照并保存的操作

IEM模型,地表粗糙度模拟

利用微波反演土壤水分时候,利用IEM模型可以实现对随机地表的模拟

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

上一篇: 进阶数据库系列(二):PostgreSQL 目录结构与配置文件 postgresql.conf 详解
下一篇: 进阶数据库系列(四):PostgreSQL 访问控制与认证管理
pgdba
博客等级 码龄4年 30粉丝 31原创
评论 1
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值