For the multi‐access channel wireless sensor network scenario with limited channel resources, the transmission of real‐time information needs to consider the channel environment, spectrum utilization and the freshness of information. First, we present a cognitive network model where secondary user (SU) shares the primary user (PU) spectrum through the underlay scheme. The sensor nodes with energy harvesting (EH) capabilities dynamically monitor changes in the surrounding environment and transmit status updates to the common secondary destination node. Considering the stability of the data queue in the SU as well as the working state and stable service interference constraints of PU, an optimization problem of minimizing the average AoI and average peak AoI (PAoI) of the EH node is proposed. Second, two policies are used to solve the above problems, including the decentralized probabilistic‐random‐access (PRA) policy and the drift plus penalty (DPP) policyin. In PRA policy, two SU nodes make independent transmission decisions based on corresponding probability distributions, and in DPP policy, the Lyapunov optimization framework is used to optimize scheduling decisions in the timeslots for optimizing the age of data packets. The simulation results show that the optimization of AoI under the DPP policy is more significant than the PRA policy, which can effectively improve the timeliness and freshness of data packets.