重庆思庄Oracle、Redhat认证学习论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 1119|回复: 0
打印 上一主题 下一主题

[Oracle] Oracle通过SQL语句查数据库服务器IP信息

[复制链接]
跳转到指定楼层
楼主
发表于 2022-11-17 10:59:26 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
文档课题:Oracle通过SQL语句查数据库服务器IP信息.
数据库:oracle 11.2.0.464
系统:centos 7.964
1hosts文件
/etc/hosts文件内容如下:
#PublicIP (ens33)
192.168.133.210hisdb1
192.168.133.211hisdb2
#PrivateIP (ens37)
192.168.11.110hisdb1-priv
192.168.11.111hisdb2-priv
#VirtualIP (ens33)
192.168.133.212hisdb1-vip
192.168.133.213hisdb2-vip
#Scan IP(ens33)
192.168.133.214hisdb-scan
192.168.133.215hisdbdg
2sql查询
public ip及主机名.
SQL>col PUBLIC_IP for a20
SQL> colhostname for a15
SQL>select utl_inaddr.get_host_address PUBLIC_IP,utl_inaddr.get_host_name HOSTNAMEfrom dual;
PUBLIC_IP            HOSTNAME
-----------------------------------
192.168.133.210      hisdb1
dbms包查主机名和ip
SQL>set serveroutput on
SQL> begin
  2 dbms_output.put_line(utl_inaddr.get_host_name);
  3 dbms_output.put_line(utl_inaddr.get_host_address);
  4  end;
  5  /
hisdb1
192.168.133.210
PL/SQLprocedure successfully completed.
rac publicip.
SQL>select * from v$configured_interconnects;
NAME            IP_ADDRESS       IS_ SOURCE
------------------------------- --- -------------------------------
ens37:1         169.254.207.21   NO
ens33           192.168.133.210  YES
ens33:1         192.168.133.214  YES
ens33:3         192.168.133.212  YES
SQL> col"RAC Device" for a15
SQL> selectindx          as "InterfaceIndex",
       inst_id       as "RAC Instance",
       pub_ksxpia    as "Public?",
       picked_ksxpia as "RAC Device",
       name_ksxpia   as "NIC Device",
       ip_ksxpia    as "IP Address"
  from x$ksxpia;
InterfaceIndex RAC Instance Public?    RACDevice      NIC Device      IP Address
--------------------------- ---------- --------------- --------------- ----------------
              0            1 N          GPnP            ens37:1         169.254.207.21
              1            1 Y          GPnP            ens33           192.168.133.210
              2            1 Y          GPnP            ens33:1         192.168.133.214
              3            1 Y          GPnP            ens33:3         192.168.133.212
注意:只显示本节点公网IP、VIP和ScanIP,无法查到私网 IP.
SingleDB查IP
SQL>col host for a15
SQL>col ip for a15
SQL>r
  1 select sys_context('USERENV', 'SERVER_HOST') as HOST,
  2        utl_inaddr.get_host_address(sys_context('USERENV', 'SERVER_HOST')) as IP
  3*  from dual
HOST            IP
------------------------------
hisdbdg         192.168.133.215
3shell查询
查实例名.
[oracle@hisdb1~]$ ps -ef|grep ora_smon|grep -v grep
oracle     4080     1  0 16:45 ?        00:00:00 ora_smon_orcl1
[oracle@hisdb1~]$ ps -ef | grep ora_smon | grep -v grep| awk -F" " '{print $8}'|awk -F"_" '{print $3}'
orcl1
查IP.
[oracle@hisdb1 ~]$ grep -w $HOSTNAME /etc/hosts| grep -v vip | grep -vpriv| awk -F" " '{print $1}'
192.168.133.210
[oracle@hisdb1 ~]$ ping `hostname` -c 1
PING hisdb1 (192.168.133.210) 56(84) bytes of data.
64 bytes from hisdb1 (192.168.133.210): icmp_seq=1 ttl=64 time=0.038 ms
--- hisdb1 ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 0.038/0.038/0.038/0.000 ms
[oracle@hisdb1 ~]$ ping `hostname` -c 1 | grep PING  
PING hisdb1 (192.168.133.210) 56(84) bytes of data.
[oracle@hisdb1 ~]$ ping `hostname` -c 1 | grep PING | cut -d '(' -f2
192.168.133.210) 56
[oracle@hisdb1 ~]$ ping `hostname` -c 1 | grep PING | cut -d '(' -f2  | cut -d ')' -f1
192.168.133.210
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 支持支持 反对反对
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|手机版|小黑屋|重庆思庄Oracle、Redhat认证学习论坛 ( 渝ICP备12004239号-4 )

GMT+8, 2024-7-1 18:34 , Processed in 0.140837 second(s), 21 queries .

重庆思庄学习中心论坛-重庆思庄科技有限公司论坛

© 2001-2020

快速回复 返回顶部 返回列表