Thứ Ba, 15 tháng 9, 2026

ORA-12154: Cannot connect to database khi impdp

1.VẤN ĐỀ

@service không nhận, lỗi như bên dưới:

[oracle@testgold1 gold]$ impdp "'sys/oracle@testgold26pdb1 as sysdba'"      DIRECTORY=DUMP_GOLD     DUMPFILE=gold.expdp.meta.cus_all_new1.20260814.f01.dmp     LOGFILE=impdp.gold_meta.new1_26.20260915.log     CONTENT=METADATA_ONLY     PARALLEL=8     CLUSTER=NO     METRICS=YES     LOGTIME=ALL

Import: Release 23.26.3.0.0 - Production on Tue Sep 15 10:45:37 2026
Version 23.26.3.0.0

Copyright (c) 1982, 2026, Oracle and/or its affiliates.  All rights reserved.

UDI-12154: operation generated ORACLE error 12154
ORA-12154: Cannot connect to database. Cannot find alias testgold26pdb1 in /u01/app/oracle/product/26ai/dbhome_1/network/admin/tnsnames.ora.
Help: https://docs.oracle.com/error-help/db/ora-12154/

[oracle@testgold1 gold]$ sqlplus / as sysdba

SQL*Plus: Release 23.26.3.0.0 - Production on Tue Sep 15 10:47:52 2026
Version 23.26.3.0.0

Copyright (c) 1982, 2026, Oracle.  All rights reserved.


Connected to:
Oracle AI Database 26ai Enterprise Edition Release 23.26.3.0.0 - Production
Version 23.26.3.0.0

SQL> connect sys/oracle@testgold26pdb1 as sysdba;
ERROR:
ORA-12154: Cannot connect to database. Cannot find alias testgold26pdb1 in
/u01/app/oracle/product/26ai/dbhome_1/network/admin/tnsnames.ora.
Help: https://docs.oracle.com/error-help/db/ora-12154/ [oracle@testgold1 gold]$ tnsping testgold26pdb1
 
 TNS Ping Utility for Linux: Version 23.26.3.0.0 - Production on 15-SEP-2026 10:48:09
 
 Copyright (c) 1997, 2026, Oracle.  All rights reserved.
 
 Used parameter files:
 
 TNS-03505: Failed to resolve name
 [oracle@testgold1 gold]$ lsnrctl  status
 
 LSNRCTL for Linux: Version 23.26.3.0.0 - Production on 15-SEP-2026 10:48:15
 
 Copyright (c) 1991, 2026, Oracle.  All rights reserved.
 
 Connecting to (ADDRESS=(PROTOCOL=tcp)(HOST=)(PORT=1521))
 STATUS of the LISTENER
 ------------------------
 Alias                     LISTENER
 Version                   TNSLSNR for Linux: Version 19.0.0.0.0 - Production
 Start Date                07-SEP-2026 09:08:09
 Uptime                    7 days 18 hr. 40 min. 6 sec
 Trace Level               off
 Security                  ON: Local OS Authentication
 SNMP                      OFF
 Listener Log File         /u01/app/oracle/diag/tnslsnr/testgold1/listener/alert/log.xml
Listening Endpoints Summary...
   (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=testgold1)(PORT=1521)))
 Services Summary...
 Service "55e26f11a7283483e063499b5e64773f" has 2 instance(s).
   Instance "testbill26", status READY, has 1 handler(s) for this service...
   Instance "testgold26", status READY, has 1 handler(s) for this service...
 Service "5b0a9ec4851b5a9be06322ca020ae061" has 1 instance(s).
   Instance "testgold26", status READY, has 1 handler(s) for this service...
 Service "5b685446b384920de06322ca020af7ca" has 1 instance(s).
   Instance "testbill26", status READY, has 1 handler(s) for this service...
 Service "testbill" has 1 instance(s).
   Instance "testbill", status READY, has 1 handler(s) for this service...
 Service "testbill26" has 1 instance(s).
   Instance "testbill26", status READY, has 1 handler(s) for this service...
 Service "testbill26XDB" has 1 instance(s).
   Instance "testbill26", status READY, has 1 handler(s) for this service...
 Service "testbill26pdb" has 1 instance(s).
   Instance "testbill26", status READY, has 1 handler(s) for this service...
 Service "testbill26pdb1" has 1 instance(s).
   Instance "testbill26", status READY, has 1 handler(s) for this service...
 Service "testbillXDB" has 1 instance(s).
   Instance "testbill", status READY, has 1 handler(s) for this service...
 Service "testgold" has 1 instance(s).
   Instance "testgold", status READY, has 1 handler(s) for this service...
 Service "testgold26" has 1 instance(s).
   Instance "testgold26", status READY, has 1 handler(s) for this service...
 Service "testgold26XDB" has 1 instance(s).
   Instance "testgold26", status READY, has 1 handler(s) for this service...
 Service "testgold26pdb1" has 1 instance(s).
   Instance "testgold26", status READY, has 1 handler(s) for this service...
 Service "testgoldXDB" has 1 instance(s).
   Instance "testgold", status READY, has 1 handler(s) for this service...
 The command completed successfully

2.NGUYÊN NHÂN

Lỗi ORA-12154/TNS-03505 ở đây là bình thường — service testgold26pdb1 đã đăng ký thành công trên listener (thấy rõ trong lsnrctl status), nhưng chưa có alias tương ứng trong tnsnames.ora. Bạn đang dùng cú pháp @testgold26pdb1 như một TNS alias, nhưng file tnsnames chưa khai báo alias này.

3.GIẢI PHÁP

Cách 1 — Fix nhanh nhất: dùng Easy Connect (không cần sửa tnsnames.ora)

bash
# Vì đang chạy local trên chính host testgold1, dùng Easy Connect Plus:
impdp "'sys/oracle@//testgold1:1521/testgold26pdb1 as sysdba'" \
    DIRECTORY=DUMP_GOLD \
    DUMPFILE=gold.expdp.meta.cus_all_new1.20260814.f01.dmp \
    LOGFILE=impdp.gold_meta.new1_26.20260915.log \
    CONTENT=METADATA_ONLY \
    PARALLEL=8 \
    CLUSTER=NO \
    METRICS=YES \
    LOGTIME=ALL

Kiểm tra trước bằng sqlplus để chắc chắn connect được:

bash
sqlplus "sys/oracle@//testgold1:1521/testgold26pdb1 as sysdba"

Lưu ý: dấu $ trong password cần escape bằng \$ khi gõ trực tiếp trong bash (double quote), hoặc dùng single quote bên ngoài như anh đang làm.

Cách 2 — Thêm alias vào tnsnames.ora (khuyến nghị nếu dùng lại nhiều lần)

bash
# Kiểm tra đúng TNS_ADMIN đang trỏ vào đâu
echo $TNS_ADMIN
env | grep TNS

# Xác nhận file thực sự đang được đọc là file nào
cat /u01/app/oracle/product/26ai/dbhome_1/network/admin/tnsnames.ora

Thêm entry:

bash
cat >> /u01/app/oracle/product/26ai/dbhome_1/network/admin/tnsnames.ora << 'EOF'

TESTGOLD26PDB1 =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = testgold1)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = testgold26pdb1)
    )
  )
EOF

Test lại:

bash
tnsping testgold26pdb1
sqlplus "sys/oracle@testgold26pdb1 as sysdba"

Vì sao tnsping báo "Failed to resolve name" mà không báo lỗi file?

Output tnsping của anh có dòng:

Used parameter files:

(để trống — không hiện đường dẫn file nào). Điều này thường có nghĩa TNS_ADMIN chưa được set hoặc đang trỏ sai thư mục, nên tnsping/impdp không tìm đúng file tnsnames.ora mà anh vừa sửa. Kiểm tra:

bash
# Nếu TNS_ADMIN rỗng, set lại đúng theo ORACLE_HOME 26ai
export TNS_ADMIN=/u01/app/oracle/product/26ai/dbhome_1/network/admin
echo $TNS_ADMIN

# Đảm bảo set permanent trong profile của user oracle
grep TNS_ADMIN ~/.bash_profile ~/.bashrc

Checklist xác nhận trước khi chạy lại impdp

bash
# 1. Đúng ORACLE_HOME 26ai đang active
echo $ORACLE_HOME
which impdp sqlplus tnsping

# 2. Đúng TNS_ADMIN
echo $TNS_ADMIN
ls -la $TNS_ADMIN/tnsnames.ora

# 3. Service thực sự đang READY (đã xác nhận ở lsnrctl status của anh — OK)

# 4. Test connect trước khi chạy impdp
sqlplus "sys/oracle@//testgold1:1521/testgold26pdb1 as sysdba"

Cách 1 (Easy Connect) là lựa chọn nhanh nhất để chạy ngay job import đang chờ; Cách 2 giúp chuẩn hóa lâu dài nếu team còn dùng alias testgold26pdb1 cho các job khác (RMAN, Data Guard, GoldenGate...).

=============================
TƯ VẤN: Click Here hoặc Hotline/Zalo 090.29.12.888
=============================
Website không chứa bất kỳ quảng cáo nào, mọi đóng góp để duy trì phát triển cho website (donation) xin vui lòng gửi về STK 90.2142.8888 - Ngân hàng Vietcombank Thăng Long - TRAN VAN BINH
=============================
Nếu bạn không muốn bị AI thay thế và tiết kiệm 3-5 NĂM trên con đường trở thành DBA chuyên nghiệp hay làm chủ Database thì hãy đăng ký ngay KHOÁ HỌC ORACLE DATABASE A-Z ENTERPRISE, được Coaching trực tiếp từ tôi với toàn bộ bí kíp thực chiến, thủ tục, quy trình của gần 20 năm kinh nghiệm (mà bạn sẽ KHÔNG THỂ tìm kiếm trên Internet/Google) từ đó giúp bạn dễ dàng quản trị mọi hệ thống Core tại Việt Nam và trên thế giới, đỗ OCP.
- CÁCH ĐĂNG KÝ: Gõ (.) hoặc để lại số điện thoại hoặc inbox https://m.me/tranvanbinh.vn hoặc Hotline/Zalo 090.29.12.888
- Chi tiết tham khảo:
https://bit.ly/oaz_w
=============================
2 khóa học online qua video giúp bạn nhanh chóng có những kiến thức nền tảng về Linux, Oracle, học mọi nơi, chỉ cần có Internet/4G:
- Oracle cơ bản: https://bit.ly/admin_1200
- Linux: https://bit.ly/linux_1200
=============================
KẾT NỐI VỚI CHUYÊN GIA TRẦN VĂN BÌNH:
📧 Mail: binhoracle@gmail.com
☎️ Mobile/Zalo: 0902912888
👨 Facebook: https://www.facebook.com/BinhOracleMaster
👨 Inbox Messenger: https://m.me/101036604657441 (profile)
👨 Fanpage: https://www.facebook.com/tranvanbinh.vn
👨 Inbox Fanpage: https://m.me/tranvanbinh.vn
👨👩 Group FB: https://www.facebook.com/groups/DBAVietNam
👨 Website: https://www.tranvanbinh.vn
👨 Blogger: https://tranvanbinhmaster.blogspot.com
🎬 Youtube: https://www.youtube.com/@binhguru
👨 Tiktok: https://www.tiktok.com/@binhguru
👨 Linkin: https://www.linkedin.com/in/binhoracle
👨 Twitter: https://twitter.com/binhguru
👨 Podcast: https://www.podbean.com/pu/pbblog-eskre-5f82d6
👨 Địa chỉ: Tòa nhà Sun Square - 21 Lê Đức Thọ - Phường Mỹ Đình 1 - Quận Nam Từ Liêm - TP.Hà Nội

=============================
cơ sở dữ liệu, cơ sở dữ liệu quốc gia, database, AI, trí tuệ nhân tạo, artificial intelligence, machine learning, deep learning, LLM, ChatGPT, DeepSeek, Grok, oracle tutorial, học oracle database, Tự học Oracle, Tài liệu Oracle 12c tiếng Việt, Hướng dẫn sử dụng Oracle Database, Oracle SQL cơ bản, Oracle SQL là gì, Khóa học Oracle Hà Nội, Học chứng chỉ Oracle ở đầu, Khóa học Oracle online,sql tutorial, khóa học pl/sql tutorial, học dba, học dba ở việt nam, khóa học dba, khóa học dba sql, tài liệu học dba oracle, Khóa học Oracle online, học oracle sql, học oracle ở đâu tphcm, học oracle bắt đầu từ đâu, học oracle ở hà nội, oracle database tutorial, oracle database 12c, oracle database là gì, oracle database 11g, oracle download, oracle database 19c/21c/23c/23ai, oracle dba tutorial, oracle tunning, sql tunning , oracle 12c, oracle multitenant, Container Databases (CDB), Pluggable Databases (PDB), oracle cloud, oracle security, oracle fga, audit_trail,oracle RAC, ASM, oracle dataguard, oracle goldengate, mview, oracle exadata, oracle oca, oracle ocp, oracle ocm , oracle weblogic, postgresql tutorial, mysql tutorial, mariadb tutorial, ms sql server tutorial, nosql, mongodb tutorial, oci, cloud, middleware tutorial, docker, k8s, micro service, hoc solaris tutorial, hoc linux tutorial, hoc aix tutorial, unix tutorial, securecrt, xshell, mobaxterm, putty

ĐỌC NHIỀU

Trần Văn Bình - Oracle Database Master