Ambari postgres数据库操作
1.先切换用户
[root@anode1 ~]# su postgres
bash-4.2$
2.用psql命令登录PostgreSQL控制台
默认的用户和数据库是postgres
bash-4.2$ psql
could not change directory to "/root"
psql (9.2.18)
Type "help" for help.
postgres=#
3.进入ambari库
切换数据库,相当于mysql的use dbname
postgres=# \c ambari
You are now connected to database "ambari" as user "postgres".
4.授予ambari用户对ambari库的权限
ambari=# grant postgres to ambari;
GRANT ROLE
ambari=# grant all privileges on database ambari to ambari;
GRANT
5.退出
ambari=# \q
You have new mail in /var/spool/mail/root
6.重新使用amabri用户进入postgresql(默认密码bigdata)
bash-4.2$ psql -U ambari
could not change directory to "/root"
Password for user ambari:
psql (9.2.18)
Type "help" for help.
7.列举数据库
列举数据库,相当于mysql的show databases
ambari=> \l
List of databases
Name | Owner | Encoding | Collate | Ctype | Access privileges
-----------+----------+----------+-------------+-------------+-----------------------
ambari | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =Tc/postgres +
| | | | | postgres=CTc/postgres+
| | | | | ambari=CTc/postgres
postgres | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
template0 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/postgres +
| | | | | postgres=CTc/postgres
template1 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/postgres +
| | | | | postgres=CTc/postgres
(4 rows)
8.列举表
列举表,相当于mysql的show tables(当前已经在ambari数据库)
ambari=> \dtList of relationsSchema | Name | Type | Owner
--------+-------------------------------+-------+----------ambari | adminpermission | table | postgresambari | adminprincipal | table | postgresambari | adminprincipaltype | table | postgresambari | adminprivilege | table | postgresambari | adminresource | table | postgresambari | adminresourcetype | table | postgresambari | alert_current | table | postgresambari | alert_definition | table | postgresambari | alert_group | table | postgresambari | alert_group_target | table | postgresambari | alert_grouping | table | postgresambari | alert_history | table | postgresambari | alert_notice | table | postgresambari | alert_target | table | postgresambari | alert_target_states | table | postgresambari | ambari_operation_history | table | postgresambari | ambari_sequences | table | postgresambari | artifact | table | postgresambari | blueprint | table | postgresambari | blueprint_configuration | table | postgresambari | blueprint_setting | table | postgresambari | cluster_version | table | postgresambari | clusterconfig | table | postgresambari | clusterconfigmapping | table | postgresambari | clusterhostmapping | table | postgresambari | clusters | table | postgresambari | clusterservices | table | postgresambari | clusterstate | table | postgres
ambari | confgroupclusterconfigmapping | table | postgresambari | configgroup | table | postgresambari | configgrouphostmapping | table | postgresambari | execution_command | table | postgresambari | extension | table | postgresambari | extensionlink | table | postgresambari | groups | table | postgresambari | host_role_command | table | postgresambari | host_version | table | postgresambari | hostcomponentdesiredstate | table | postgresambari | hostcomponentstate | table | postgresambari | hostconfigmapping | table | postgresambari | hostgroup | table | postgresambari | hostgroup_component | table | postgresambari | hostgroup_configuration | table | postgresambari | hosts | table | postgresambari | hoststate | table | postgresambari | kerberos_descriptor | table | postgresambari | kerberos_principal | table | postgresambari | kerberos_principal_host | table | postgresambari | key_value_store | table | postgresambari | members | table | postgresambari | metainfo | table | postgresambari | permission_roleauthorization | table | postgresambari | qrtz_blob_triggers | table | postgresambari | qrtz_calendars | table | postgresambari | qrtz_cron_triggers | table | postgresambari | qrtz_fired_triggers | table | postgresambari | qrtz_job_details | table | postgresambari | qrtz_locks | table | postgresambari | qrtz_paused_trigger_grps | table | postgresambari | qrtz_scheduler_state | table | postgresambari | qrtz_simple_triggers | table | postgresambari | qrtz_simprop_triggers | table | postgresambari | qrtz_triggers | table | postgresambari | remoteambaricluster | table | postgresambari | remoteambariclusterservice | table | postgresambari | repo_version | table | postgres
ambari | request | table | postgresambari | requestoperationlevel | table | postgresambari | requestresourcefilter | table | postgresambari | requestschedule | table | postgresambari | requestschedulebatchrequest | table | postgresambari | role_success_criteria | table | postgresambari | roleauthorization | table | postgresambari | servicecomponent_history | table | postgresambari | servicecomponentdesiredstate | table | postgresambari | serviceconfig | table | postgresambari | serviceconfighosts | table | postgresambari | serviceconfigmapping | table | postgresambari | servicedesiredstate | table | postgresambari | setting | table | postgresambari | stack | table | postgresambari | stage | table | postgresambari | topology_host_info | table | postgresambari | topology_host_request | table | postgresambari | topology_host_task | table | postgresambari | topology_hostgroup | table | postgresambari | topology_logical_request | table | postgresambari | topology_logical_task | table | postgresambari | topology_request | table | postgresambari | upgrade | table | postgresambari | upgrade_group | table | postgresambari | upgrade_item | table | postgresambari | users | table | postgresambari | viewentity | table | postgresambari | viewinstance | table | postgresambari | viewinstancedata | table | postgresambari | viewinstanceproperty | table | postgresambari | viewmain | table | postgresambari | viewparameter | table | postgresambari | viewresource | table | postgresambari | viewurl | table | postgresambari | widget | table | postgresambari | widget_layout | table | postgresambari | widget_layout_user_widget | table | postgres
(104 rows)
9.查看表结构
相当于desc tblname
ambari=> \d usersTable "ambari.users"Column | Type | Modifiers
-----------------------+-----------------------------+---------------------------------------------user_id | integer | not nullprincipal_id | bigint | not nullldap_user | integer | not null default 0user_name | character varying(255) | not nulluser_type | character varying(255) | not null default 'LOCAL'::character varyingcreate_time | timestamp without time zone | default now()user_password | character varying(255) | active | integer | not null default 1active_widget_layouts | character varying(1024) | default NULL::character varying
Indexes:"pk_users" PRIMARY KEY, btree (user_id)"unq_users_0" UNIQUE CONSTRAINT, btree (user_name, user_type)
Foreign-key constraints:"fk_users_principal_id" FOREIGN KEY (principal_id) REFERENCES adminprincipal(principal_id)
Referenced by:TABLE "members" CONSTRAINT "fk_members_user_id" FOREIGN KEY (user_id) REFERENCES users(user_id)
ambari=> \d host_versionTable "ambari.host_version"Column | Type | Modifiers
-----------------+-----------------------+-----------id | bigint | not nullrepo_version_id | bigint | not nullhost_id | bigint | not nullstate | character varying(32) | not null
Indexes:"pk_host_version" PRIMARY KEY, btree (id)
Foreign-key constraints:"fk_host_version_host_id" FOREIGN KEY (host_id) REFERENCES hosts(host_id)"fk_host_version_repovers_id" FOREIGN KEY (repo_version_id) REFERENCES repo_version(repo_version_id)
10.Select查询
ambari=> select * from host_version;id | repo_version_id | host_id | state
----+-----------------+---------+---------1 | 1 | 1 | CURRENT3 | 1 | 3 | CURRENT2 | 1 | 2 | CURRENT
(3 rows)
11.退出
ambari=> \q
You have new mail in /var/spool/mail/root
bash-4.2$ exit
exit
You have new mail in /var/spool/mail/root
[root@anode1 ~]#
命令小结
- 查看所有库:\l
- 查看所有表:\dt
- 查看一个表的结构: \d 表名
- 换数据库 \c dbName
Ambari postgres数据库操作相关推荐
- 一个通用数据库操作组件DBUtil(c#)、支持SqlServer、Oracle、Mysql、postgres、SQLITE
这是一个.net下操作数据库(结构数据库)的工具类,支持sqlserver.oracle.mysql.postgres.sqlite.access等常见数据库. 注意:它并不是一个orm工具(常见的o ...
- mysql数据迁移到sqlserver_一个通用数据库操作组件DBUtil(c#)、支持SqlServer、Oracle、Mysql、postgres、SQLITE...
这是一个.net下操作数据库(结构数据库)的工具类,支持sqlserver.oracle.mysql.postgres.sqlite.access等常见数据库. 注意:它并不是一个orm工具(常见的o ...
- oledb vc访问mdb数据库_一个通用数据库操作组件DBUtil(c#)、支持SqlServer、Oracle、Mysql、postgres、SQLITE...
这是一个.net下操作数据库(结构数据库)的工具类,支持sqlserver.oracle.mysql.postgres.sqlite.access等常见数据库. 注意:它并不是一个orm工具(常见的o ...
- freecplus框架-PostgreSQL数据库操作
文章目录 一.源代码说明 二.概述 三.connection类 四.sqlstatement类 五.程序流程 1.无结果集SQL的程序的流程 2.有结果集SQL的程序的流程 六.示例程序 1.创建超女 ...
- Postgres 数据库大批量单表导入数据引发性能故障的处理
因公司经营管理策略原因,我们地区部门还是以开发外包和产品服务为主,对测试外包服务销售工作要求占比不高,而测试部门本来有四五个性能测试人员,加上老员工都比较积极做事在测试团队建设管理上不用花费太多精力. ...
- 【使用QGIS入库将shp数据导入postgis、postgres数据库】
使用QGIS入库将shp数据导入postgis.postgres数据库 第一步,安装并打开QGIS软件 第二步,连接PostGIS数据库 在弹出的连接信息界面中配置数据库连接参数 输入数据库连接参数后 ...
- postgresql数据库操作
postgresql数据库操作 1.数据库基本操作 创建数据库 查看所有数据库 进入数据库 删除数据库 退出数据库 2.数据库修改操作 修改数据库名称 1.数据库基本操作 创建数据库 create d ...
- mysql数据库转postgres数据库语法不通错误方言
之前一直用的是mysql数据库,现在公司要求使用postgres,但是做分页查询的时候,postgres数据库会报错如下: mysql使用的是limit x,y.而postgres使用方式是limit ...
- [Kong 与 Konga 与 Postgres数据库] 之 Kuberneres 部署
1.Kong的概述 Kong是一个clould-native.快速的.可扩展的.分布式的微服务抽象层(也称为API网关.API中间件或在某些情况下称为服务网格)框架.Kong作为开源项目在2015年推 ...
最新文章
- HTTP请求报文和HTTP响应报文(转)
- C# WPF Application 下的文件操作
- mysql数据库管理文件_数据库管理中文件的使用_MySQL
- 轻松解决Python “字符编码”,玩儿爬虫的朋友最爱这个库!
- 16位汇编 在代码段中使用数据
- Spark Java API:Transformation
- 【LeetCode - 1765】. 地图中的最高点
- jupyter notebook 安装教程
- mysql集群搭建.pdf,内容太过真实
- Windows cmd 颜色,字体,color font set up
- python带cookie提交表单自动登录(转)
- python学习-----------argparse
- 安全微软微软安全新闻聚焦-双周刊第三十二期
- 如何用pdb命令调试python代码
- u盘ios刻录_ISO to USB(ISO刻录到U盘)下载|ISO to USB(ISO刻录到U盘)官方下载-太平洋下载中心...
- EovaJFinal在阿里云K8S实现多环境自动化部署
- 日语学习之——五十音图及单词(3)
- 【奥斯卡理财星体系 第五章】丨手把手教你从零开始搭建资产配置
- 西门子_Step7软件仿真方法
- 苹果手机找回ID及密码经验
热门文章
- java.bankaccount_java编写BankAccount类
- PC微信聊天记录迁移
- 怎么用浏览器访问一个web服务器的某个文件
- 蓬莱小课:一线城市数据分析师岗位薪酬有多少?
- 插入排序实现——直接插入排序和希尔排序
- 在hyper-v虚拟机上挂载windows主机文件夹
- silverlight数据绑定模式TwoWay,OneWay,OneTime的研究
- 干货 | 什么是磁传感器?最常用的磁传感器类型及应用
- PS学习记录-图像【像素】与【分辨率】的说明
- python获取标签属性值_Python爬虫库BeautifulSoup获取对象(标签)名,属性,内容,注释