热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

Ambaripostgres数据库操作

1.先切换用户[root@anode1~]#supostgresbash-4.2$2.用psql命令登录PostgreSQL控制台默认的用户和数据库是postgresbash-4

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=> \dt
List of relations
Schema | Name | Type | Owner
--------+-------------------------------+-------+----------
ambari | adminpermission | table | postgres
ambari | adminprincipal | table | postgres
ambari | adminprincipaltype | table | postgres
ambari | adminprivilege | table | postgres
ambari | adminresource | table | postgres
ambari | adminresourcetype | table | postgres
ambari | alert_current | table | postgres
ambari | alert_definition | table | postgres
ambari | alert_group | table | postgres
ambari | alert_group_target | table | postgres
ambari | alert_grouping | table | postgres
ambari | alert_history | table | postgres
ambari | alert_notice | table | postgres
ambari | alert_target | table | postgres
ambari | alert_target_states | table | postgres
ambari | ambari_operation_history | table | postgres
ambari | ambari_sequences | table | postgres
ambari | artifact | table | postgres
ambari | blueprint | table | postgres
ambari | blueprint_configuration | table | postgres
ambari | blueprint_setting | table | postgres
ambari | cluster_version | table | postgres
ambari | clusterconfig | table | postgres
ambari | clusterconfigmapping | table | postgres
ambari | clusterhostmapping | table | postgres
ambari | clusters | table | postgres
ambari | clusterservices | table | postgres
ambari | clusterstate | table | postgres
ambari | confgroupclusterconfigmapping | table | postgres
ambari | configgroup | table | postgres
ambari | configgrouphostmapping | table | postgres
ambari | execution_command | table | postgres
ambari | extension | table | postgres
ambari | extensionlink | table | postgres
ambari | groups | table | postgres
ambari | host_role_command | table | postgres
ambari | host_version | table | postgres
ambari | hostcomponentdesiredstate | table | postgres
ambari | hostcomponentstate | table | postgres
ambari | hostconfigmapping | table | postgres
ambari | hostgroup | table | postgres
ambari | hostgroup_component | table | postgres
ambari | hostgroup_configuration | table | postgres
ambari | hosts | table | postgres
ambari | hoststate | table | postgres
ambari | kerberos_descriptor | table | postgres
ambari | kerberos_principal | table | postgres
ambari | kerberos_principal_host | table | postgres
ambari | key_value_store | table | postgres
ambari | members | table | postgres
ambari | metainfo | table | postgres
ambari | permission_roleauthorization | table | postgres
ambari | qrtz_blob_triggers | table | postgres
ambari | qrtz_calendars | table | postgres
ambari | qrtz_cron_triggers | table | postgres
ambari | qrtz_fired_triggers | table | postgres
ambari | qrtz_job_details | table | postgres
ambari | qrtz_locks | table | postgres
ambari | qrtz_paused_trigger_grps | table | postgres
ambari | qrtz_scheduler_state | table | postgres
ambari | qrtz_simple_triggers | table | postgres
ambari | qrtz_simprop_triggers | table | postgres
ambari | qrtz_triggers | table | postgres
ambari | remoteambaricluster | table | postgres
ambari | remoteambariclusterservice | table | postgres
ambari | repo_version | table | postgres
ambari | request | table | postgres
ambari | requestoperationlevel | table | postgres
ambari | requestresourcefilter | table | postgres
ambari | requestschedule | table | postgres
ambari | requestschedulebatchrequest | table | postgres
ambari | role_success_criteria | table | postgres
ambari | roleauthorization | table | postgres
ambari | servicecomponent_history | table | postgres
ambari | servicecomponentdesiredstate | table | postgres
ambari | serviceconfig | table | postgres
ambari | serviceconfighosts | table | postgres
ambari | serviceconfigmapping | table | postgres
ambari | servicedesiredstate | table | postgres
ambari | setting | table | postgres
ambari | stack | table | postgres
ambari | stage | table | postgres
ambari | topology_host_info | table | postgres
ambari | topology_host_request | table | postgres
ambari | topology_host_task | table | postgres
ambari | topology_hostgroup | table | postgres
ambari | topology_logical_request | table | postgres
ambari | topology_logical_task | table | postgres
ambari | topology_request | table | postgres
ambari | upgrade | table | postgres
ambari | upgrade_group | table | postgres
ambari | upgrade_item | table | postgres
ambari | users | table | postgres
ambari | viewentity | table | postgres
ambari | viewinstance | table | postgres
ambari | viewinstancedata | table | postgres
ambari | viewinstanceproperty | table | postgres
ambari | viewmain | table | postgres
ambari | viewparameter | table | postgres
ambari | viewresource | table | postgres
ambari | viewurl | table | postgres
ambari | widget | table | postgres
ambari | widget_layout | table | postgres
ambari | widget_layout_user_widget | table | postgres
(104 rows)

9.查看表结构

相当于desc tblname

ambari=> \d users
Table "ambari.users"
Column | Type | Modifiers
-----------------------+-----------------------------+---------------------------------------------
user_id | integer | not null
principal_id | bigint | not null
ldap_user | integer | not null default 0
user_name | character varying(255) | not null
user_type | character varying(255) | not null default 'LOCAL'::character varying
create_time | timestamp without time zone | default now()
user_password | character varying(255) |
active | integer | not null default 1
active_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_version
Table "ambari.host_version"
Column | Type | Modifiers
-----------------+-----------------------+-----------
id | bigint | not null
repo_version_id | bigint | not null
host_id | bigint | not null
state | 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 | CURRENT
3 | 1 | 3 | CURRENT
2 | 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

推荐阅读
  • 树莓派语音控制的配置方法和步骤
    本文介绍了在树莓派上实现语音控制的配置方法和步骤。首先感谢博主Eoman的帮助,文章参考了他的内容。树莓派的配置需要通过sudo raspi-config进行,然后使用Eoman的控制方法,即安装wiringPi库并编写控制引脚的脚本。具体的安装步骤和脚本编写方法在文章中详细介绍。 ... [详细]
  • 本文介绍了Oracle数据库中tnsnames.ora文件的作用和配置方法。tnsnames.ora文件在数据库启动过程中会被读取,用于解析LOCAL_LISTENER,并且与侦听无关。文章还提供了配置LOCAL_LISTENER和1522端口的示例,并展示了listener.ora文件的内容。 ... [详细]
  • iOS超签签名服务器搭建及其优劣势
    本文介绍了搭建iOS超签签名服务器的原因和优势,包括不掉签、用户可以直接安装不需要信任、体验好等。同时也提到了超签的劣势,即一个证书只能安装100个,成本较高。文章还详细介绍了超签的实现原理,包括用户请求服务器安装mobileconfig文件、服务器调用苹果接口添加udid等步骤。最后,还提到了生成mobileconfig文件和导出AppleWorldwideDeveloperRelationsCertificationAuthority证书的方法。 ... [详细]
  • 基于Socket的多个客户端之间的聊天功能实现方法
    本文介绍了基于Socket的多个客户端之间实现聊天功能的方法,包括服务器端的实现和客户端的实现。服务器端通过每个用户的输出流向特定用户发送消息,而客户端通过输入流接收消息。同时,还介绍了相关的实体类和Socket的基本概念。 ... [详细]
  • 如何自行分析定位SAP BSP错误
    The“BSPtag”Imentionedintheblogtitlemeansforexamplethetagchtmlb:configCelleratorbelowwhichi ... [详细]
  • Spring源码解密之默认标签的解析方式分析
    本文分析了Spring源码解密中默认标签的解析方式。通过对命名空间的判断,区分默认命名空间和自定义命名空间,并采用不同的解析方式。其中,bean标签的解析最为复杂和重要。 ... [详细]
  • ZSI.generate.Wsdl2PythonError: unsupported local simpleType restriction ... [详细]
  • 本文介绍了如何使用C#制作Java+Mysql+Tomcat环境安装程序,实现一键式安装。通过将JDK、Mysql、Tomcat三者制作成一个安装包,解决了客户在安装软件时的复杂配置和繁琐问题,便于管理软件版本和系统集成。具体步骤包括配置JDK环境变量和安装Mysql服务,其中使用了MySQL Server 5.5社区版和my.ini文件。安装方法为通过命令行将目录转到mysql的bin目录下,执行mysqld --install MySQL5命令。 ... [详细]
  • 本文介绍了将mysql从5.6.15升级到5.7.15的详细步骤,包括关闭访问、备份旧库、备份权限、配置文件备份、关闭旧数据库、安装二进制、替换配置文件以及启动新数据库等操作。 ... [详细]
  • Imtryingtofigureoutawaytogeneratetorrentfilesfromabucket,usingtheAWSSDKforGo.我正 ... [详细]
  • Spring学习(4):Spring管理对象之间的关联关系
    本文是关于Spring学习的第四篇文章,讲述了Spring框架中管理对象之间的关联关系。文章介绍了MessageService类和MessagePrinter类的实现,并解释了它们之间的关联关系。通过学习本文,读者可以了解Spring框架中对象之间的关联关系的概念和实现方式。 ... [详细]
  • 如何查询zone下的表的信息
    本文介绍了如何通过TcaplusDB知识库查询zone下的表的信息。包括请求地址、GET请求参数说明、返回参数说明等内容。通过curl方法发起请求,并提供了请求示例。 ... [详细]
  • 移动端常用单位——rem的使用方法和注意事项
    本文介绍了移动端常用的单位rem的使用方法和注意事项,包括px、%、em、vw、vh等其他常用单位的比较。同时还介绍了如何通过JS获取视口宽度并动态调整rem的值,以适应不同设备的屏幕大小。此外,还提到了rem目前在移动端的主流地位。 ... [详细]
  • 本文介绍了如何使用PHP代码将表格导出为UTF8格式的Excel文件。首先,需要连接到数据库并获取表格的列名。然后,设置文件名和文件指针,并将内容写入文件。最后,设置响应头部,将文件作为附件下载。 ... [详细]
  • Activiti7流程定义开发笔记
    本文介绍了Activiti7流程定义的开发笔记,包括流程定义的概念、使用activiti-explorer和activiti-eclipse-designer进行建模的方式,以及生成流程图的方法。还介绍了流程定义部署的概念和步骤,包括将bpmn和png文件添加部署到activiti数据库中的方法,以及使用ZIP包进行部署的方式。同时还提到了activiti.cfg.xml文件的作用。 ... [详细]
author-avatar
我家在波力牧场
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有